防止需要将 NuGet.exe 添加到源代码管理 [英] Prevent needing to add NuGet.exe to source control

查看:15
本文介绍了防止需要将 NuGet.exe 添加到源代码管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些背景:
我遵循了关于在不提交包的情况下使用 NuGet 的教程 取得了一些成功.在解决这个NuGet问题之后,通过手动添加和nuget.targets 文件的 一切正常.

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:

无法找到C:...Visual Studio 2010ProjectsMyProject.nuget uget.exe"

Unable to locate 'C:...Visual Studio 2010ProjectsMyProject.nuget uget.exe'

这是有道理的,因为我的忽略模式阻止我检入 exe 文件.从 this related SO question 我推断将此文件置于版本控制中并不少见(或者是吗?),但是真的,我不想将 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?

我已经尝试了一些谷歌功能,浏览了文档,并摆弄了 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,但这并没有按预期工作(有或没有条件属性).

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:

Change the value to 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 添加到源代码管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆