Search code examples
c#.net.net-coremauivisual-studio-2022

NETSDK1201: For projects targeting .NET 8.0 and higher, specifying a RuntimeIdentifier will no longer produce a self contained app by default


After updating Visual Studio 2022 Community to version 17.8.0, Visual Studio is unable to select the right framework for executing The project.

I have a solution with 2 projects that must run under "Multiple Startup projects", Both projects (MAUI and WebApi) run on dotnet 7.0. I updated the Visual Studio to the latest version and now I am unable to run the projects. The visual studio executes the target file in the SDK/8.0.

I am looking for a way to overwrite this behavior, for example: instead of running the target file from the .net 8, it runs in .net 7. Or any other solution that could fix this issue.

2>C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(251,5): warning NETSDK1201: For projects targeting .NET 8.0 and higher, specifying a RuntimeIdentifier will no longer produce a self contained app by default. To continue building self-contained apps, set the SelfContained property to true or use the --self-contained argument.
2>C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(251,5): warning NETSDK1201: For projects targeting .NET 8.0 and higher, specifying a RuntimeIdentifier will no longer produce a self contained app by default. To continue building self-contained apps, set the SelfContained property to true or use the --self-contained argument.
2>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(4911,5): warning MSB3026: Could not copy "C:\Users\marco\.nuget\packages\xamarin.firebase.ios.core\8.10.0.3\lib\net6.0-ios15.4\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\Headers\GoogleUtilitiesComponents-umbrella.h" to "bin\Debug\net7.0-ios\iossimulator-x64\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\Headers\GoogleUtilitiesComponents-umbrella.h". Beginning retry 7 in 1000ms. Could not find a part of the path 'bin\Debug\net7.0-ios\iossimulator-x64\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\Headers\GoogleUtilitiesComponents-umbrella.h'.
2>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(4911,5): warning MSB3026: Could not copy "C:\Users\marco\.nuget\packages\xamarin.firebase.ios.core\8.10.0.3\lib\net6.0-ios15.4\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\PrivateHeaders\GULCCComponentContainerInternal.h" to "bin\Debug\net7.0-ios\iossimulator-x64\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\PrivateHeaders\GULCCComponentContainerInternal.h". Beginning retry 7 in 1000ms. Could not find a part of the path 'bin\Debug\net7.0-ios\iossimulator-x64\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\PrivateHeaders\GULCCComponentContainerInternal.h'.

Solution

  • Edit

    After making changes defined Original Answer, I started to receive an error "warning MSB3026: Could not copy [long path]\xamarin.firebase.ios.core\8.10.0.3\ to [LongPathToBin\xamarin.firebase.ios.core\8.10.0.3"

    to solve that, we need to set windows to accept long paths

    I run this command in PowerShell as an Admin

    New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
    -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
    

    references:

    warning MSB3026

    global.json


    Original Answer

    Thanks to Serg who gave a great tip to fix my issue.

    let's describe what I did:

    I create a global.json file and include it in the same directory of my solution. I added the framework information I want to target by default (after the update to Visual Studio Community 17.8.0, the default .net framework becomes 8.0 instead of 7.0 of the latest version). global.json file

    {
      "sdk": {
        "version": "7.0.404",
        "rollForward": "latestMinor"
      }
    }
    

    You need to reinstall the Maui workflow (if you are using MAUI)

    Open the developer powershell window inside the Visual Studio (Ctrl+`) and execute the following command:

    dotnet workload restore
    

    Close the visual studio and delete the .vs folder in the same folder as your solution.

    After that, I closed and reopened the visual studio and started multiple projects that finally worked!