admin管理员组

文章数量:1180537

I have a solution which build fine on my local workstation and is configure to build 6 and 8:

<Project Sdk="Microsoft.NET.Sdk" xmlns=";>
  <PropertyGroup>
...
    <TargetFrameworks>net8.0;net6.0</TargetFrameworks>
...
  </PropertyGroup>
</Project>

However, as soon as I try to compile inside a pipeline on our DevOps system I get the following error message:

F:\Agent1_work_tool\dotnet\sdk\8.0.405\Microsoft.Common.CurrentVersion.targets(1890,5): warning NU1702: ProjectReference 'F:\Agent1_work\1546\s\Tools\XXXX.csproj' was resolved using '.NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v6.0'. This project may not be fully compatible with your project. [F:\Agent1_work\1546\s\Tools_Test\XXXX.csproj::TargetFramework=net6.0] F:\Agent1_work_tool\dotnet\sdk\8.0.405\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1005: Assets file 'F:\Agent1_work\1546\s\Tools\Build\obj\project.assets.json' doesn't have a target for 'net48'. Ensure that restore has run and that you have included 'net48' in the TargetFrameworks for your project. [F:\Agent1_work\1546\s\Tools\XXXX.csproj::TargetFramework=net48]

Even when I use a CMD script and explicitly state which framework to use:

dotnet build "XXXX.sln" --configuration Release --framework net6.0

I did used UseDotNet@2 to download the needed versions so they should be available.

    - task: UseDotNet@2
      displayName:              "Get .NET6"
      inputs:
        packageType:            "sdk"
        version:                "6.x"
        vsVersion:              "22.x"
    - task: UseDotNet@2
      displayName:              "Get .NET8"
      inputs:
        packageType:            "sdk"
        version:                "8.x"
        vsVersion:              "22.x.x"

Update 1:

The global.json is currently empty:

{
}

Update 2:

I already use the NuGetToolInstaller to install 6.x.

    - task: NuGetToolInstaller@1
      displayName:              "Get NuGet 6"
      inputs:
        versionSpec:            '6.x'

Update 3:

I just found several references like this inside the project files:

    <Reference Include="log4net">
      <HintPath>..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
    </Reference>
    <PackageReference Include="log4net" Version="3.0.3" />

I'm going to remove all duplicates and HintPath.

I have a solution which build fine on my local workstation and is configure to build .net6 and .net8:

<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
...
    <TargetFrameworks>net8.0;net6.0</TargetFrameworks>
...
  </PropertyGroup>
</Project>

However, as soon as I try to compile inside a pipeline on our DevOps system I get the following error message:

F:\Agent1_work_tool\dotnet\sdk\8.0.405\Microsoft.Common.CurrentVersion.targets(1890,5): warning NU1702: ProjectReference 'F:\Agent1_work\1546\s\Tools\XXXX.csproj' was resolved using '.NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v6.0'. This project may not be fully compatible with your project. [F:\Agent1_work\1546\s\Tools_Test\XXXX.csproj::TargetFramework=net6.0] F:\Agent1_work_tool\dotnet\sdk\8.0.405\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1005: Assets file 'F:\Agent1_work\1546\s\Tools\Build\obj\project.assets.json' doesn't have a target for 'net48'. Ensure that restore has run and that you have included 'net48' in the TargetFrameworks for your project. [F:\Agent1_work\1546\s\Tools\XXXX.csproj::TargetFramework=net48]

Even when I use a CMD script and explicitly state which framework to use:

dotnet build "XXXX.sln" --configuration Release --framework net6.0

I did used UseDotNet@2 to download the needed .net versions so they should be available.

    - task: UseDotNet@2
      displayName:              "Get .NET6"
      inputs:
        packageType:            "sdk"
        version:                "6.x"
        vsVersion:              "22.x"
    - task: UseDotNet@2
      displayName:              "Get .NET8"
      inputs:
        packageType:            "sdk"
        version:                "8.x"
        vsVersion:              "22.x.x"

Update 1:

The global.json is currently empty:

{
}

Update 2:

I already use the NuGetToolInstaller to install 6.x.

    - task: NuGetToolInstaller@1
      displayName:              "Get NuGet 6"
      inputs:
        versionSpec:            '6.x'

Update 3:

I just found several references like this inside the project files:

    <Reference Include="log4net">
      <HintPath>..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
    </Reference>
    <PackageReference Include="log4net" Version="3.0.3" />

I'm going to remove all duplicates and HintPath.

Share Improve this question edited 11 hours ago Martin asked yesterday MartinMartin 11.8k16 gold badges85 silver badges115 bronze badges 9
  • 1 What is in your global.json? – Richard Commented yesterday
  • 1 Try using the NugetToolInstaller@1 with version 6.x, as suggested in stackoverflow.com/a/77839104/558486. See also stackoverflow.com/questions/54817553/… – Rui Jarimba Commented yesterday
  • 1 Does the project that you show have a ProjectReference to Tools\XXXX.csproj? Is the Tools\XXXX.csproj project a .Net Framework v4.8 project that can be changed to netstandard2.0? (See NuGet Warning NU1702) – Jonathan Dodds Commented yesterday
  • 1 Suggest you specify a version of .NET SDK in global.json (can build down level, so v8 SDK can build v6 target). And, what task are you using to do the build? – Richard Commented yesterday
  • 1 netstandard2.0 can be used with net6.0. Is the same version of Visual Studio installed and available for both the local builds and for the pipeline build? – Jonathan Dodds Commented 20 hours ago
 |  Show 4 more comments

1 Answer 1

Reset to default 1

Answering my own question: The environment variable TargetFramework=net48 was defined on the build machine. Must have been there for a very long time and it overwrites everything else. The documentation suggests not to use the environment variable and I'll agree so I removed it. Now it works like a charm.

This may or may not break some of the other build pipelines but I'll deal with that when it happens.

本文标签: netWhy is dotnet build using the wrong framework in a DevOps pipeline (NU1702)Stack Overflow