Build error of ASP.NET Core - “…current settings, version 2.1.0-preview3-26411-06 would be used instead”

后端 未结 10 1413
南方客
南方客 2021-02-07 20:18

I\'ve created a sample project using dotnet, but I get the following error when building the project:

error : The project was restored using Mic

相关标签:
10条回答
  • 2021-02-07 20:39

    I have a somehow different solution, working for ASP.NET 2.1, as I had problems with both building and publishing processes:

    <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
            <TargetFramework>netcoreapp2.1</TargetFramework>
            <RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion> --> fix publishing issues
            <PlatformTarget>AnyCPU</PlatformTarget> --> fix publishing issues
        </PropertyGroup>
        <ItemGroup>
            <PackageReference Update="Microsoft.NETCore.App" Version="2.1.0" /> --> fix building issues
            <ProjectReference Include="..\PublicSonar.Monitor.Persistent.Json\PublicSonar.Monitor.Persistent.Json.csproj" />
        </ItemGroup>
    </Project>
    
    0 讨论(0)
  • 2021-02-07 20:43

    Use:

    <Project Sdk="Microsoft.NET.Sdk.Web">
    
        <PropertyGroup>
            <TargetFramework>netcoreapp2.1</TargetFramework>
            <UserSecretsId>aspnet-...............245435</UserSecretsId>
            <RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
            <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
        </PropertyGroup>
    
        <ItemGroup>
            <PackageReference Include="Microsoft.AspNetCore.App" />
            <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" PrivateAssets="All" />
        </ItemGroup>
        <ItemGroup>
            <PackageReference Update="Microsoft.NETCore.App" Version="2.1.1" />
        </ItemGroup>
    </Project>
    
    0 讨论(0)
  • 2021-02-07 20:44

    The specific error I was getting was

    error : NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.0.5, but with current settings, version 2.1.1 would be used instead.

    I had

    <ItemGroup>
        <PackageReference Update="Microsoft.NETCore.App" Version="2.0.5" />
    </ItemGroup>```
    

    further down the file. Once I removed this and did a clean, the project built successfully.

    0 讨论(0)
  • 2021-02-07 20:51

    Just because you have the latest SDK installed doesn't mean you have the latest runtime installed. I'll never quite understand that.

    Run dotnet --info.

    I got the following (only the latest installed versions are shown here).

     .NET Core SDKs installed:
       2.1.300 [C:\Program Files\dotnet\sdk]
    
     .NET Core runtimes installed:d\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    
    • So I installed 2.1.1 runtime, and now dotnet --info gives me 2.1.1 as well.

    • Oh and 2.1.3 actually is 2.1.1, but they had to increment it for some reason I don't fully understand about or care about.

    • I restarted Visual Studio, because it never seems to be able to keep versions in sync

    • I added the following to PropertyGroup in my .csproj file (unload project + edit)

      netcoreapp2.1 2.1.1

    Now I thought we didn't need to specify this this any more, and this .csproj file was just created brand new today and it didn't have a runtime version at all. Whatever we're supposed to be doing, this worked for me. I also found this massive thread about versioning with 2.1.1 which I skimmed over, but it seems there are complications with point releases right now, so maybe this specific version is necessary.


    I ended up here because of this error:

    error : The project was restored using Microsoft.NETCore.App version 2.1.1, but with current settings, version 2.1.0 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore.

    Adding RuntimeFrameworkVersion was the specific fix for that that worked.

    Unfortunately there isn't any linked article for this error message, which would be helpful.

    0 讨论(0)
  • 2021-02-07 20:52

    I had a similar error message:

    The project was restored using Microsoft.NETCore.App version 2.0.7, but with current settings, version 2.0.0 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore

    I added the RuntimeFrameworkVersion setting to the .csproj file, and it fixed an issue for me:

    <PropertyGroup>
       <TargetFramework>netcoreapp2.0</TargetFramework>
       <RuntimeFrameworkVersion>2.0.7</RuntimeFrameworkVersion><!--here is the fix-->
    </PropertyGroup>
    
    <ItemGroup>
       <PackageReference Update="Microsoft.NETCore.App" Version="2.0.7" />
    </ItemGroup>
    
    0 讨论(0)
  • 2021-02-07 20:57

    It seems Visual Studio is using different .NET Core versions for restore/build/publish.

    To resolve this issue, you could add TargetLatestRuntimePatch attribute in the .csproj file:

    <PropertyGroup>
       <TargetFramework>netcoreapp2.0</TargetFramework>
       <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
    </PropertyGroup>
    

    For details, please see this page.

    0 讨论(0)
提交回复
热议问题