Search code examples
c#.netvisual-studiomsbuildcsproj

.Net project always rebuilds, not up to date caused by CopyLocal property


No matter what I do my .net Project will always rebuild. I read this Article https://oz-code.com/blog/visual-studio-keeps-rebuilding-projects-no-good-reason/, and I found the CopyLocal problem in my Project.

I got this message: Project 'PROJECTNAME' is not up to date. CopyLocal reference 'D:\...PROJECTPATH...\bin\x64\Debug\System.Net.Http.dll' is missing from output location..

My System.Net.Http.dll is referenced like this (Don't ask me why Private is set twice): .csproj reference

Visual Studio itself shows me it is taken from the "Reference Assemblies": enter image description here

And as I figured out, Assemblies taken from the "Reference Assemblies" are never copied to the output folder.

Now the problem, if I change the CopyLocal to false it works, but after any NuGet restore it will be set to True again. I assume this is caused by the fact that the HintPath is refereing to a NuGet package where CopyLocal should be set to True.

It only happens with "System.*" references. The Project is .net 4.8 and I'm using the latest VS2019.

Is there any way to prevent this, or did i miss something how I can fix this? This is happening in a quite big solution and it takes forever to build if everything is rebuilt all the time.

I tried ReSharper-Build, and that worked but if possible i would like to stick to the standard.

Thank you for any help.


Solution

  • Is there any way to prevent this, or did i miss something how I can fix this? This is happening in a quite big solution and it takes forever to build if everything is rebuilt all the time.

    As Hans said, you reference two system.net.http.dll in the same project in different ways so that it creates a build mess, making it impossible to determine the version of the reference. And it turns always rebuild.

    In fact, System.Net.Http.dll is just a part of Net Framework4.8 and exists in the Reference assemblies.

    All of this points to the fact that this is a public,global DLL that can be used directly in VS without having to install it using nuget. So I'm curious why you're still using nuget to install it.

    Note: When you create a new net frameowrk4.8 project and then open reference, and you will find that it already references system.net.http.dll from Reference assemblies. So when you use nuget to install it or use the path of the nuget in the HintPath, it will not change the inital path.

    Solution

    To solve it, please uninstall the nuget package System.Net.Http.Right-click on the project-->Manage Nuget Packages--> uninstall it.

    enter image description here

    Hope it could help you.