VS2010,SP2010:NuGet包未添加到web.config

时间:2012-10-19 22:55:31

标签: visual-studio visual-studio-2008 sharepoint-2010

这是我的第一个Visual Studio 2010 / SharePoint 2010 Visual Web部件,也是我第一次使用NuGet,所以请原谅我的盲目无知。 fwiw,这是SP2010。我在这里问而不是在sharepoint.stackexchange,因为我怀疑它更像是一个VS问题。

在VS2010中,我有一个SP2010 Visual Web Part项目。它调试干净并显示一个基本的“Hello World!”如预期的。看看VisualWebPart1UserControl.ascx.cs,我有

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;

namespace VisualWebPartProject1.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SPSite site = SPContext.Current.Site;
            SPSite.UsageInfo usage = site.Usage;
            foo.Text = "Hello World!";
        }
    }
}

到目前为止一切顺利。现在我真正想在这个页面上做的事情将涉及一些丑陋的日期/时间工作,所以我谷歌,并发现一个NuGet包,“TimePeriodLibrary.NET”。我让NuGet配置为使用VS2010,我将包添加到我的项目中。我看到参考文献中添加的包装reveryrences,太棒了。

当我尝试这个时出现问题:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Itenso.TimePeriod;

namespace VisualWebPartProject1.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SPSite site = SPContext.Current.Site;
            SPSite.UsageInfo usage = site.Usage;

              TimeRange timeRange1 = new TimeRange(
              new DateTime(2011, 2, 22, 14, 0, 0),
              new DateTime(2011, 2, 22, 18, 0, 0));
              foo.Text = "TimeRange1: " + timeRange1;
        }
    }
}

看起来没问题,但是当我调试时,我得到了:

"Could not load file or assembly 'Itenso.TimePeriod, Version=1.4.11.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748' or one of its dependencies. The system cannot find the file specified.":"Itenso.TimePeriod, Version=1.4.11.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748"

作为我第一次使用NuGet(您可以告诉其他第一次),我的印象是它会修改web.config并基本上“让它工作”。我已经绝望地尝试将所需的.DLL手动拖动到Web应用程序的/ BIN文件夹中,但即使这样也无效。

我会承认,我很难过。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

我讨厌回答我自己的问题,但我确实让它发挥了作用。 http://jussionsharepoint.com/index.php/2012/02/08/using-global-assembly-cache-tool-gacutil-exe-effectively/ 我找到.dll,并使用 gacutil.exe / i 将其安装到GAC。此后,一切都按预期工作。我不能直言不讳地说这是获得理想结果的“正确”方式,但似乎是这样。我对社区希望传递的任何智慧持开放态度,如果这不是使其发挥作用的最佳方式。

答案 1 :(得分:0)

您应该右键单击引用,选择属性,然后将构建操作设置为“复制到本地”(或类似的东西)

作为旁注,nuget管理员只是在包内执行操作,所以几乎可以肯定,当出现问题时,不是经理的错。

相关问题