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