Domanda

I am attempting to compile by C# application using Mono on Ubuntu. I am trying to prevent the need to include nuget.exe in my git repository and have followed the accepted answer in this question

This works if I am using Visual Studio 2010. When I build the application, nuget.exe is downloaded as expected.

However, when I attempt to use mono and xbuild, I receive the following error.

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

The only thing I've changed is setting DownloadNuGetExe = true in nuget.targets, so that line looks like this:

<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>

My question: How can I set it so that the behavior using mono/xbuild is the same as when using Visual Studio (namely, that nuget is downloaded automatically)?

Edit This is the UsingTask line that appears in the NuGet.targets file.

<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>
È stato utile?

Soluzione

Create a script to download it. E.g.

wget http://nuget.org/nuget.exe
cp nuget.exe ./.nuget/NuGet.exe
chmod a+x ./.nuget/NuGet.exe

This keeps your NuGet.exe up to date. Source

Altri suggerimenti

This continues to be a problem today with Xamarin Studio for Business and MacOS. I encountered this error while trying to build the Facebook SDK. I had to remove the NuGet target references in the project file to make the project build. Xamarin Studio has the NuGet update built into it, so I was able to download the packages manually.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top