简体   繁体   English

.NET Core和.NET Standard项目不进行增量构建

[英].NET Core and .NET Standard projects don't do an incremental build

I'm using .NET standard libraries inside my desktop solution so I can share those libraries between my desktop and web solution. 我在桌面解决方案中使用.NET标准库,因此可以在桌面和Web解决方案之间共享这些库。 However, I'm seeing incremental build problems now. 但是,我现在看到增量构建问题。 Has anyone else experienced this or managed to fix it? 有没有其他人经历过或设法解决?

I can see that the .NET standard libraries have some incremental build features in that if I build them on the command line using "dotnet build" it takes, for example, 1 second and then if I make a code change in that library and run again it takes 2 seconds. 我可以看到.NET标准库具有一些增量生成功能,因为如果我在命令行上使用“ dotnet build”来生成它们,例如需要1秒,然后在该库中进行代码更改并运行再次需要2秒。 This goes back to 1 second if I run for a third time. 如果我第三次跑步,这可以回到1秒。

However, in pure .NET framework applications like a console app or wpf app, traditionally if you make no code change then inside visual studio it doesn't even attempt to build the project. 但是,在纯净的.NET Framework应用程序(例如控制台应用程序或wpf应用程序)中,传统上,如果您不进行任何代码更改,则在Visual Studio中甚至不会尝试构建项目。 It simply says "1 up-to-date". 它只是说“ 1最新”。 I'm seeing the .NET standard libraries always re-copied to the output directory and they also cause my entire WPF project to rebuild every time. 我看到.NET标准库总是重新复制到输出目录,并且它们还会导致我的整个WPF项目每次都重新生成。 After a while this starts to get annoying if every code change takes 5 seconds to build! 一段时间后,如果每次更改代码都需要5秒钟的时间,这就会变得很烦人!

I have at least a partial answer for you. 我至少对您有部分答案。 The issue of the binaries copying out every time is explained by Microsoft as essentially there is no support, update to a later target framework version . 微软解释了每次复制二进制文件的问题,因为基本上不存在支持,而是更新到更高的目标框架版本

At this point we don't do any smart trimming of the compat shims that come with the tooling so it ends up copying them all. 在这一点上,我们不对工具随附的compat垫片进行任何智能修整,因此最终将它们全部复制。 If you (or your dependencies) don't rely on them it is safe to delete/not-deploy them but doing it blindly may break some of your dependencies. 如果您(或您的依赖项)不依赖它们,则可以安全地删除/不部署它们,但是盲目执行可能会破坏您的某些依赖项。

And this is supposed to be fixed in 4.7.1 而这应该在4.7.1中修复

It's worth mentioning that with .NET Framework 4.7.1 and up you'll not have to deploy any extra files for .NET Standard. 值得一提的是,在.NET Framework 4.7.1及更高版本中,您无需为.NET Standard部署任何其他文件。 Today, that's already the case if you target Xamarin or .NET Core. 今天,如果您针对Xamarin或.NET Core,情况就是这样。

As for why it always copies, instead of doing so selectively as it should, I am unsure. 至于为什么总是复制,而不是应该选择性地复制,我不确定。 I have scoured build logs and I believe that the files have not been properly added to the output list of a build target but it is difficult to diagnose. 我已经搜索过构建日志,并且我相信这些文件没有正确地添加到构建目标的输出列表中,但是很难诊断。 Visual Studio also has smart ways to entirely avoid invoking MSBuild, so logic in the MSBuild script to skip a target doesn't even have to run. Visual Studio还具有完全避免调用MSBuild的聪明方法,因此MSBuild脚本中跳过目标的逻辑甚至不必运行。 Visual Studio is mostly a black box, but I suspect this logic is broken too, based on the behavior both you and I have observed. Visual Studio主要是一个黑匣子,但是基于您和我所观察到的行为,我怀疑这种逻辑也被打破了。

This is a frustrating issue because there are still good reasons to target old versions of .NET Framework, for example if a library is distributed to a customer who may build against it using Visual Studio 2013, and cannot be expected to update. 这是一个令人沮丧的问题,因为仍然有充分的理由将旧版本的.NET Framework作为目标,例如,如果将库分发给了可能使用Visual Studio 2013对其构建的客户,并且无法期望对其进行更新。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM