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 | Show 4 more comments1 Answer
Reset to default 1Answering 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
版权声明:本文标题:.net - Why is dotnet build using the wrong framework in a DevOps pipeline (NU1702) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738176560a2067280.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
global.json
? – Richard Commented yesterdayNugetToolInstaller@1
with version6.x
, as suggested in stackoverflow.com/a/77839104/558486. See also stackoverflow.com/questions/54817553/… – Rui Jarimba Commented yesterdayProjectReference
toTools\XXXX.csproj
? Is theTools\XXXX.csproj
project a .Net Framework v4.8 project that can be changed tonetstandard2.0
? (See NuGet Warning NU1702) – Jonathan Dodds Commented yesterdayglobal.json
(can build down level, so v8 SDK can build v6 target). And, what task are you using to do the build? – Richard Commented yesterdaynetstandard2.0
can be used withnet6.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