'The installation of Visual Studio 2022 causes Visual Studio 2019 to not find system references at runtime
We have a solution with about 40 projects. One of these projects is a Microsoft Service Fabric project we use to host all micro services present in this solution. Projects in this solution use different frameworks: .NET 4.7, .NET Standard 2.0 and .NET Core 3.1
Every developer in our department currently uses Visual Studio 2019 to build and debug this exact solution without any problems. Now one developer got a new machine on which we tried to use Visual Studio 2022. On the first try to build this solution in 2022 we got the following error:
Error MSB4226 The imported project "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Also, tried to find "Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" in the fallback search path(s) for $(MSBuildExtensionsPath32) - "C:\Program Files (x86)\MSBuild" . These search paths are defined in "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe.Config". Confirm that the path in the declaration is correct, and that the file exists on disk in one of the search paths.
After changing the path in the import section of the affected project to Visual Studio 2022 (by replacing v16.0 with v17.0) we were able to build and also to debug the different projects without any problems.
The problem occurred after we switched back to Visual Studio 2019. After resetting the changed path from the error message before back to Visual Studio 2019, we were able to build but not to debug the solution anymore. Once we tried to start the Service Fabric project we would always get the following exception:
System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Source=System.Web.Http StackTrace: at System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes) at ... (some of your code)
Inner Exception 1: FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
The code that throws the exception looks like this:
public static HttpConfiguration HttpConfiguration { get; set; }
private static void InitializeHttpConfiguration()
{
if (HttpConfiguration != null)
return;
HttpConfiguration = new HttpConfiguration(); //this is the line that throws the exception
HttpConfiguration.MapHttpAttributeRoutes();
}
Has anyone experienced the same issue and maybe got a solution already? Upgrading everyone at once is unfortunately not so easy because we also have automated build servers that have to be upgraded too. And so do all release pipelines we use.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
