I am getting an error in Visual Studio 2022 Preview 2.1 when trying to build a specific project. The class library is targeting .NET 5 for Windows using the TargetFramework moniker net5.0-windows. The class library is used for a WPF project so it also contains the tag <UseWPF>true</UseWPF>. The error occurs when a XAML file in the project is using an attached dependency property defined in the project. I then get the following error:
..\..\..\..\..\..\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets (429, 7):
Could not copy the file "C:\Users\andre\AppData\Local\NCrunch\13492\1\ClassLibrary1\obj\ClassLibrary1.csproj.nuget.dgspec.json" because it was not found.
The same project works in the latest version of Visual Studio 2019.
I have a reproduced the error in a minimal project file which I can provide if needed.
For me this project doesn't work on VS2019 either. This is caused by the preview SDK. Microsoft has made some changes that will trigger the msbuild cli to use the preview SDK when not run under visual studio if it's installed. See here for more information.
If you add a global.json file that tells msbuild to not use the preview the project compiles under NCrunch under VS19/21.
{
"sdk": {
"allowPrerelease": false
}
}
With this being a preview release I'm hesitant to see if this needs fixing on our end.
For me this project doesn't work on VS2019 either.
My apologies, I forgot to mention that it only worked on VS2019 for me when I uninstalled VS2022. So yes, it doesn't work for me either in VS2019 nor VS2022 when both are installed. I added the global.json as you mentioned, and that did the trick. Thank you for your help and quick feedback!