[英]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.