简体   繁体   English

生成后如何下载NuGet作为.csproj文件的一部分,以便创建.nupkg文件?

[英]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. 我有一个C#项目,其中包含一些.dll,我想将其打包为.nupkg文件。 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 . 当nuget.exe已经下载到.nuget文件夹中时,此方法工作正常,但是当nuget.exe不存在时,即使.nuget \\ NuGet.targets文件具有DownloadNuGetExe设置为true ,它也不会自动DownloadNuGetExe

After some investigation, it seems that nuget.exe will not download if there are no packages to import. 经过一番调查,似乎如果没有要导入的软件包,nuget.exe将不会下载。 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). 但是我需要下载nuget.exe,以便它可以在开发人员机器和构建服务器上创建一个.nupkg文件(而不是管理导入到项目中的包/引用)。

How can I work around this limitation? 如何解决此限制? I would prefer a solution that modifies only the .csproj file. 我希望使用仅修改.csproj文件的解决方案。

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. 不知道这是否是最好的解决方案,但是我们通常将nuget.exe放在.nuget文件夹中,并确保将其检入源代码管理中,以便在开发人员提取最新代码时才将其下载。

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. 这不是最优雅的解决方案,但是由于实际上我们对代码进行了nuget化处理,因此我们不再拥有包含所有内容的庞然大物解决方案,因此我们发现每个解决方案/项目都需要以某种方式提供自己的nuget.exe。 This approach has been working for us, hope it works for you too...! 这种方法对我们一直有效,希望它也对您有用...!

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

<CallTarget Targets="_DownloadNuGet" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在csproj文件中设置LIB环境变量? - How can I set the LIB environment variable inside a csproj file? 如何更新应用程序中每个 .csproj 文件中的 ToolVersion - How can I update the ToolVersion in every .csproj file in my application 如何在Visual Studio 2010中恢复损坏的.csproj文件? - How can I recover a corrupt .csproj file in Visual Studio 2010? 如何在Angular上创建下载文件服务? - How can I create a download file service on Angular? 如何在没有visual studio的情况下将新文件添加到.csproj文件中 - How can I add a new file to .csproj file without visual studio 如何创建指向共享文档库的快捷方式文件,以便可以通过电子邮件将其发送给其他人 - How can i create a shortcut file to a sharepoint document library so that i can email it to people 如何使用 C# HttpClient 下载大文件的一部分 - how can I use C# HttpClient to download a part of large file 如何在我的新 CSPROJ 类库中包含带有本机 dll 的 NuGet 包? - How can I include a NuGet package with native dlls in my new CSPROJ Class Library? 如何使用 webview 下载 xamarin 中的文件? - How can I download file in xamarin with webview? 如何在 angular 6 中下载 excel 文件 - How can I download an excel file in angular 6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM