简体   繁体   中英

How can I download NuGet after build as part of a .csproj file so that I can create a .nupkg file?

I have a C# project that has some .dll I would like to package up in to a .nupkg file. This works fine when nuget.exe is downloaded already to the .nuget folder, but when nuget.exe is not present it will not download automatically, even though the .nuget\\NuGet.targets file has a setting DownloadNuGetExe which has been set to true .

After some investigation, it seems that nuget.exe will not download if there are no packages to import. But I require nuget.exe to be downloaded so that it can create a .nupkg file on developer machines and on a build server (and not to manage importing packages/references in to the project).

How can I work around this limitation? I would prefer a solution that modifies only the .csproj file.

Not sure if this is the best solution, but we generally put the nuget.exe into the .nuget folder, and ensure that this gets checked into source control so that it just gets downloaded when the developers pull down the latest code.

It's not the most elegant solution, but since we actually nuget-ized our code & thus we no longer have a monster solution that contains everything, we discovered that every solution/project needs to provision its own nuget.exe somehow. This approach has been working for us, hope it works for you too...!

通过导入.nuget \\ NuGet.targets文件,然后像这样调用名为_DownloadNuGet的目标,我们设法找到了解决方案:

<CallTarget Targets="_DownloadNuGet" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM