Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在TeamCity中包含NuGet软件包_C#_Windows Services_Teamcity_Nuget_.net 4.5 - Fatal编程技术网

C# 在TeamCity中包含NuGet软件包

C# 在TeamCity中包含NuGet软件包,c#,windows-services,teamcity,nuget,.net-4.5,C#,Windows Services,Teamcity,Nuget,.net 4.5,我最近开始使用NuGet来管理外部包。目前,我只在NLog中需要它。 当我在VS 2012中构建项目时,一切正常。但是,我尝试将TeamCity作为CI服务器(我对CI相当陌生),它给了我以下错误: [Csc] SomeNamespace\SomeClass.cs(10, 7): error CS0246: The type or namespace name 'NLog' could not be found (are you missing a using directive or an

我最近开始使用NuGet来管理外部包。目前,我只在NLog中需要它。 当我在VS 2012中构建项目时,一切正常。但是,我尝试将TeamCity作为CI服务器(我对CI相当陌生),它给了我以下错误:

[Csc] SomeNamespace\SomeClass.cs(10, 7): error CS0246: 
The type or namespace name 'NLog' could not be found 
(are you missing a using directive or an assembly reference?)
(此错误在我使用NLog的地方反复出现)

现在,我没有在SVN中包含“packages/”文件夹,因为我认为不包含二进制文件并让TeamCity中的MSBuild自己下载这些文件是一个很好的做法。然而,它显然没有这样做。我确实在SVN中包含了“packages.xml”文件。 我可以检查什么来确定出了什么问题

更新 多亏了@DavidBrabant,我才朝着正确的方向前进。但是,我现在在TeamCity中遇到以下错误:

Package restore is disabled by default. To give consent, open the Visual Studio Options dialog, 
click on Package Manager node and check 'Allow NuGet to download missing packages during build.'
但是,我不在Visual Studio中,而是在TeamCity中,所以我不知道如何将“同意”设置为true!我尝试在NuGet.targets文件中将RestorePackages设置为“true”:

<RestorePackages Condition="  '$(RestorePackages)' == '' ">true</RestorePackages>
true
但这不起作用

更新2 为了使其正常工作,我还设置了以下属性NuGet.targets:

<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'true' ">false</RequireRestoreConsent>
false

这使得构建成功运行

NuGet内置的启用包还原功能允许您非常轻松地设置工作流的预构建部分。要执行此操作,请在Visual Studio的解决方案资源管理器中的解决方案节点上单击鼠标右键,然后单击“启用NuGet包还原”选项。请注意,您需要在系统上安装NuGet Visual Studio扩展。如果您这样做了,但仍然没有看到此菜单项出现,则说明您已经启用了此选项,或者您的解决方案目录中有一个名为.nuget的文件夹

设置该选项后,您现在可以删除包安装目录中的所有子文件夹,默认情况下为$(SolutionDir)\packages,但repositories.config文件除外,并且您的解决方案仍应正确编译。在编译过程中,您应该在VisualStudio输出窗口中看到NuGet安装跟踪,并且还应该看到所需的NuGet软件包重新出现在软件包安装目录中


另请参见。

仅重申更新2。如果您无意中发现TeamCity没有下载NuGet软件包,请尝试更改这一行

<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'true' ">false</RequireRestoreConsent>
true
这条线

<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'true' ">false</RequireRestoreConsent>
false

NuGet.targets
文件中,它应该可以工作。

在TeamCity v8中,我能够使用TC中的环境变量解决“restore package”错误

见:


env.EnableNuGetPackageRestore
作为项目级别的环境变量设置为“true”,将解决所有生成配置的问题。这样做感觉比编辑NuGet.targets文件imho要好一点。

看看这篇文章:


如上所述,我添加了第一个构建步骤“NuGet Installer”,进行了一些共同配置,现在包被自动还原。

您可以从CI机器连接到NuGet存储库(可以ping吗)?您启用了包还原吗?实际上,将构建项目所需的所有内容都放在存储库中是最佳做法。Mate,也许我真的很笨,但我花了很多时间才明白最后一个字符串必须看起来像
false
我认为指定正确的字符串是有意义的,而不是它的初始版本。谢谢Seekeer,我相应地更改了它!我没有目标。它不应该用于包还原。我尝试了Nate Rickard上面的环境变量fix,但它不起作用。@Bounz的修复对我来说非常有效。我同意。这里有类似的信息:现在已被集成到MSBuild和中的自动包还原所取代