问题描述
某些环境:
我已经按照关于在不提交软件包的情况下使用NuGet的教程取得了一些成功.解决了此NuGet问题之后,通过为nuget手动添加<RestorePackages>
和<Import ...>
来解决此问题.目标文件运行正常.
Some context:
I've followed the tutorial on using NuGet without committing packages with some success. After working around this NuGet issue by manually adding <RestorePackages>
and a <Import ...>
for the nuget.targets file things were working.
但是,一旦我用Mercurial克隆了存储库,构建时就会出现以下错误:
However, once I cloned the repository with Mercurial, I got the following error when building:
这很有意义,因为我的忽略模式使我无法检入exe文件.从这个相关的SO问题,我推断出将此文件包含在版本控制中并不少见(或者是?),但是如果可以,我真的宁愿不要将NuGet.exe提交到版本控制中.
This makes sense, because my ignore pattern prevented me from checking in the exe file. From this related SO question I inferred that it's not uncommon to have this file in version control (or is it?), but really I'd prefer not to commit NuGet.exe to version control if I can help it.
问题:是否有一种方便的方法来防止需要检入NuGet.exe?
Question: Is there a convenient way to prevent needing to check in NuGet.exe?
我尝试了一些Google-fu,整理了一下文档,并摆弄了NuGet.targets文件,但到目前为止还算不上成功.如果我可以动态地指向构建解决方案的特定环境的NuGet.exe,那似乎是可取的.
I've tried some Google-fu, skimming the documentation, and fiddling with the NuGet.targets file, no luck so far. It seems preferable if I could just dynamically point to the NuGet.exe of the particular environment that's building the solution.
我知道我可以只添加exe文件,但是我更想知道是否还有其他方法可以解决这个问题,或者知道为什么没有可行的替代方法.
I know I could just add the exe file, but I'd prefer to know if there are other ways to handle this or know why there are no viable alternatives.
更新:
nuget.targets文件包含一些相关的xml:
Update:
The nuget.targets file holds some relevant xml:
<!-- only (relevant) parts of the xml shown below -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
...
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</task>
</UsingTask>
我不熟悉.targets文件的工作原理,但这似乎与我要寻找的一致.戴着牛仔帽,我尝试将DownloadNuGetExe元素中的false
更改为true
,但这没有按预期方式工作(带有或不带有condition属性).
I'm unfamiliar with the workings of .targets files, but this seems to be along the lines of what I'm looking for. With my cowboy-coding hat on I tried changing the false
to true
in the DownloadNuGetExe element, but this didn't work as expected (with or without the condition attribute).
推荐答案
只需检查一下:nuget.targets是一个msbuild文件.而且您走对路了,
Just checked: nuget.targets is an msbuild file. And you were on the right way, in:
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
将值更改为true:
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>
但是您必须重新启动Visual Studio或重新加载解决方案(请参阅注释),才能生效.
But you must restart Visual Studio or reload the solution (see comments) after this to take effect.
这篇关于避免需要将NuGet.exe添加到源代码管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!