How to find out exactly why Visual Studio 2019 rebuilds unmodified .NET Core projects

╄→гoц情女王★ 提交于 2020-02-07 03:35:29

问题


I'm building a solution containing .NET Standard 2.0 and .NET Core 2.0 projects (C# and F#) in VS2019 (16.1.1). If I build multiple times without changes the second and subsequent builds should say "Build: 0 succeeded, 0 failed, X up-to-date", but it sometimes rebuilds some projects every time. How do I find out exactly why?

There are many SO questions and blog posts about this, most of them suggesting setting the build log verbosity to "Diagnostic" and looking for "not up to date". I've done that and the string is not found, nor is "not up-to-date" (but "up-to-date" occurs many times). So this appears to have changed in VS2019. I also know about the U2DCheckVerbosity registry setting, but that's only for .NET Framework. Reading through the build log output is unrealistic, as it's over 360 thousands lines, so I need to know what to search for.

Please note, I'm not looking for guesses as to what the problem might be - I'm looking for a way to get VS/the compiler to tell me.


回答1:


VS writes a file called NETCoreApp,Version=v2.0.AssemblyAttributes.cs into temp folder. If you build several .net core projects, the file gets changed by the other project and your VS thinks the old project is modified and builds it.

Move the generated files into the project to reduce the builds:

<PropertyGroup>
    <TargetFrameworkMonikerAssemblyAttributesFileClean>False</TargetFrameworkMonikerAssemblyAttributesFileClean>
    <TargetFrameworkMonikerAssemblyAttributesPath>$(MSBuildThisFileDirectory)SharedAssemblyAttributes.cs</TargetFrameworkMonikerAssemblyAttributesPath>
</PropertyGroup>



回答2:


I'm looking for a way to get VS/the compiler to tell me. (For VS2019)

It's hard to reproduce same issue so I'm not sure about the cause of your issue. But as for what you're asking is the way to find up-to-date related info in Output window, maybe you can check the Up To Data Checks option for .net core.

Go Tools=>Options=>Projects and Solutions=>.net core=>Up To Data Checks. Make sure you've checked the Don't call MSBuild if a project appears to be up-to-date. Then change the Logging Level to Info or Verbose.(Choose the suitable level according to your needs)

For the normal .net framework projects or C++ projects, the build output verbosity in build and run would be of great help. But when trying to find the reason why VS consider one .net core or .net standard project is out-of-date, I think we can try this option since its output is more clear.

E.g: (One .net Core project which depends on the Standard project with Info level .net core Up-To-Date Check):

And if you have too many projects in one solution, I suggest you build one project one time instead of build the whole solution so you can locate the cause of the rebuild more easily.



来源:https://stackoverflow.com/questions/57143773/how-to-find-out-exactly-why-visual-studio-2019-rebuilds-unmodified-net-core-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!