简体   繁体   English

Visual Studio Build 不会在没有项目引用的情况下下载所有 NuGet 包

[英]Visual Studio Build does not download all NuGet packages without a project reference

I'm trying to understand why removing a project reference prevents my build from downloading all the NuGet packages it needs.我试图了解为什么删除项目引用会阻止我的构建下载它需要的所有 NuGet 包。 This is with Visual Studio 2019这是 Visual Studio 2019

  • Application A (.NET 5) holds a project reference to Assembly B.应用程序 A (.NET 5) 拥有对程序集 B 的项目引用。
  • Assembly B uses a NuGet package C.程序集 B 使用 NuGet 包 C。
  • When the build starts, NuGet Package C get downloaded automatically.构建开始时,会自动下载 NuGet 包 C。

This is all vanilla expected, .NET stuff.这是所有香草预期的,.NET 的东西。

But then I realized that A does not actually use any B-specific types.但后来我意识到 A 实际上并没有使用任何 B 特定的类型。 B is a Prism Module that only loads dynamically if the user has a license for it and clicks a button. B 是一个 Prism 模块,只有在用户拥有许可证并单击按钮时才会动态加载。 So A doesn't even always load "B".所以A甚至并不总是加载“B”。

So I removed A's project reference to B. I don't want some future developer to accidentally think they can start referring to types in B. (We don't ship all modules all the time).所以我删除了 A 对 B 的项目引用。我不希望一些未来的开发人员意外地认为他们可以开始引用 B 中的类型。(我们不会一直发布所有模块)。 Technically now, there is no project in the solution that holds a reference to B. But it's still part of the build.现在从技术上讲,解决方案中没有包含对 B 的引用的项目。但它仍然是构建的一部分。 I did set up the build dependencies so that B would still build before A but there's no longer a project reference..我确实设置了构建依赖项,以便 B 仍然会在 A 之前构建,但不再有项目引用..

Then I did a clean build.然后我做了一个干净的构建。 Visual Studio said it completed successfully. Visual Studio 表示它已成功完成。 And I see Assembly B got built.我看到组装 B 已经建成。 But the build process did NOT retrieve NuGet package C (that B depends on).但是构建过程没有检索 NuGet 包 C(B 依赖)。 Testing has revealed it will not retrieve C unless application A actually holds a project reference to B.测试表明,除非应用程序 A 实际持有对 B 的项目引用,否则它不会检索 C。

Is there some way around this?有没有办法解决这个问题? If I'm building all assemblies, why would MSBuild not download all assemblies dependent NuGet packages.如果我正在构建所有程序集,为什么 MSBuild 不下载所有程序集依赖的 NuGet 包。 Is there some setting I can change to make it happen.是否有一些设置我可以更改以使其发生。

Answering my own question: I asked this question of Microsoft.回答我自己的问题:我问了微软这个问题。 They said that this behavior is by design: If a DLL-generating assembly ("B") uses a NuGet package, then the only way that package will be downloaded at build time is if an assembly that generates an EXE has a project reference to B. Merely having a build dependency is not enough.他们说,这种现象是由设计:如果DLL生成组件(“B”)采用的是NuGet包,则该包将在制作的时候下载的唯一途径是,如果生成的EXE的组件具有项目引用B. 仅仅有构建依赖是不够的。

No explanation as to why.没有解释为什么。 I still think the behavior should be different for reasons I mentioned in the question and comments above.由于我在上面的问题和评论中提到的原因,我仍然认为行为应该有所不同。 They said it is a question for the .NET team and referred it to them but I see no action on it so far.他们说这是 .NET 团队的问题并将其提交给他们,但我目前没有看到任何行动。 If I get a response, I'll post it here.如果我得到回复,我会在这里发布。

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

相关问题 使用MSBuid.exe编译项目,但未使用nuget软件包安装Visual Studio - Compile project with MSBuid.exe but without visual studio installed using nuget packages 无需重新安装即可强制重新下载解决方案和项目 NuGet 包 - Force re-download of solution and project NuGet packages without reinstall .NET Visual Studio 中的 6 个项目提供更新 NuGet 包到 7.0.0 - .NET 6 project in Visual Studio offers update NuGet packages to 7.0.0 未选中 Visual Studio 2019 项目中已安装的 nuget 包复选框 - Installed nuget packages in Visual Studio 2019 project checkbox unchecked Visual Studio 2013 - 为每个项目设置Nuget包 - Visual Studio 2013 - Setting up Nuget packages for every project 在没有Visual Studio的情况下生成Visual Studio 6项目 - Build Visual Studio 6 project without Visual Studio 没有Visual Studio的软件包管理器,如何更新nuget软件包? - How to update nuget packages without package manager of visual studio? 在Visual Studio 2015解决方案中恢复所有Nuget包 - Restoring all Nuget Packages in a Visual Studio 2015 Solution Artifactory 中的 Nuget 包未显示在 Visual Studio 中的可用包中 - Nuget package in Artifactory does not show up in available packages in Visual Studio Visual Studio + nuget + TFS:检查nuget包? - Visual Studio + nuget + TFS: checking in nuget packages?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM