我正在尝试在 Ubuntu 上使用 Mono 通过 C# 应用程序进行编译。我试图防止需要包含nuget.exe
在我的 git 存储库中,并遵循了这个问题中接受的答案
如果我使用的是 Visual Studio 2010,这将有效。当我构建应用程序时,会按预期下载 nuget.exe。
但是,当我尝试使用 mono 和 xbuild 时,我收到以下错误。
Target Build:
Project "/home/builduser/SpecialBuildProj/BuildTrade/BuildTrade.csproj" (default target(s)):
Target CheckPrerequisites:
Project "/home/builduser/SpecialBuildProj/.nuget/NuGet.targets" (_DownloadNuGet target(s)):
Target _DownloadNuGet:
: error : Error initializing task DownloadNuGet: Not registered task DownloadNuGet.
Task "DownloadNuGet" execution -- FAILED
Done building target "_DownloadNuGet" in project "/home/builduser/SpecialBuildProj/.nuget/NuGet.targets".-- FAILED
Done building project "/home/builduser/SpecialBuildProj/.nuget/NuGet.targets".-- FAILED
Task "MsBuild" execution -- FAILED
Done building target "CheckPrerequisites" in project "/home/builduser/SpecialBuildProj/BuildTrade/BuildTrade.csproj".-- FAILED
Done building project "/home/builduser/SpecialBuildProj/BuildTrade/BuildTrade.csproj".-- FAILED
Task "MSBuild" execution -- FAILED
Done building target "Build" in project "/home/builduser/SpecialBuildProj/SpecialBuildProj.sln".-- FAILED
Done building project "/home/builduser/SpecialBuildProj/SpecialBuildProj.sln".-- FAILED
我唯一更改的是设置DownloadNuGetExe
= true
in nuget.targets
,因此该行如下所示:
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>
我的问题: 如何设置它以使使用 mono/xbuild 的行为与使用 Visual Studio 时的行为相同(即自动下载 nuget)?
编辑
这是UsingTask
出现在NuGet.targets
文件中的行。
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<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>