Two project files for vs2019 and vs2022 are "colliding"

159 Views Asked by At

I have a big solution with many projects, all of them in vs2019, .net framework 4.7.2 The plan is to upgrade to .net6 by creating a project file for vs2022, and then do some #if net46 to keep backward compatibility with .net framework 4.7.2, at least in a transition period. This is working, kind of! Because this happens:

  1. I open the vs2019 project file in vs2019, and it compiles fine.
  2. Then I open the vs2022 project file in vs2022 and it compiles fine.
  3. Now, if I re-run step 1, it fails. vs2019 now tell me this:

Error CS0433 The type 'PipeAccessRule' exists in both 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'System.IO.Pipes.AccessControl, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

It turns out vs2022 installed a few nuget packages, system.security.xyz. If I delete these nuget packages from the computer, vs2019 once again compiles my project.

Why are vs2019 'detecting' the system.securiy.xyz packages if I don't have a reference to them?! (In fact, the vs2019 project uses no nugets at all)


This might not have anything to do with it, but the vs2019 .csproj file format is the 'old' format, starting with

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0">

While vs2022 is using the newer format, starting with

<Project Sdk="Microsoft.NET.Sdk">

The project has no build dependencies to other projects in the solution.


UPDATE: We just found out two interesting things:

  • If I close all instances of visual studio and open only vs2019, remove the obj-folder and recompile, it works. Not so if an instance of vs2022 is open.
  • The .net framework project compiles fine in vs2022. The errors happens only in vs2019.

I think this solves the problem at the moment. Thank's David and Bagus for your comments, you led me down the correct path.

0

There are 0 best solutions below