仅在调试版本中阻止 NuGet 还原包 [英] Prevent NuGet Restore Package in debug builds only

查看:46
本文介绍了仅在调试版本中阻止 NuGet 还原包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解决方案中启用了恢复包"选项,因此当我将代码上传到 CI 服务器时,它会更新正确构建所需的所有包,并且效果很好.现在的问题是,在我的本地机器上,构建需要很长时间才能启动,因为正在更新包".有没有办法只在发布版本中启用恢复包?

I enabled the Restore Package option in my solution so when I upload the code to the CI server it updates all the packages that it needs to build correctly, and it works great. Now the problem is that on my local machine, the build takes a long time to start because is "updating the packages". Is there a way to enable the Restore Package in release build only?

我尝试使用 falsetrue 将 .csproj 文件中的 属性移动到发布/调试部分>,但 NuGet 在打开 NuGet 控制台时更新属性并将两者都重置为 true;还尝试只在发布部分包含该属性,但随后 NuGet 将其添加到全局部分......所以我没有运气让它保持我想要的方式......

I've tried to move the <RestorePackage> property in the .csproj files to the release/debug sections with false and true, but NuGet updates the attribute when a open the NuGet console and resets both to true; also tried to only include the property in the release section, but then NuGet adds it to the global section... so I had no luck making it stay the way I want it...

有什么建议吗?

推荐答案

您现在可能已经设法回答了这个问题,但如果没有,那么这些是您需要遵循的步骤

You have probably managed to answer this by now but if not then these are the steps you need to follow

您的解决方案文件在 Windows 中的正确位置应该有一个名为 .nuget 的文件夹.重命名或删除此文件夹.

Right where your solution file is within Windows there should be a folder named .nuget. Either rename or delete this folder.

现在在记事本或任何文本编辑器中打开每个 .csproj 或 .vbproj 文件并删除这些行

Now open each .csproj or .vbproj file in notepad or any text editor and remove these lines

<RestorePackages>true</RestorePackages>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />

重要的部分是删除/重命名 .nuget 文件夹.这现在应该完全禁用包恢复.

The important part is removing/renaming the .nuget folder. This should now disable package restore completely.

要选择性地禁用 DEBUG 版本的包还原,请编辑 Nuget.settings.targets 文件并修改以下行

To selectively disable package restore for DEBUG builds edit the Nuget.settings.targets file and modify the following line

<RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages>

<RestorePackages Condition="$(RestorePackages) == '' AND '$(Configuration)' == 'Debug'">false</RestorePackages>

Nuget.settings.targets 文件位于 .nuget 文件夹下,该文件夹应与您的解决方案文件位于同一文件夹中.

The Nuget.settings.targets file is under the .nuget folder which should be in the same folder as your solution file.

这篇关于仅在调试版本中阻止 NuGet 还原包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆