microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.48k stars 2.61k forks source link

Use .NET Core Task does not enforce the version #15581

Closed Apholisha closed 10 months ago

Apholisha commented 2 years ago

Question, Bug, or Feature?
Type: Bug

Enter Task Name: Use .NET Core

Environment

Issue Description

Use .NET Core installs a .Net Core version, but that version is not what used in the subsequent tasks.

We have numerous projects that are using different versions of .Net Core ( 3.1, 5.0, 6.0) . The Task does indeed make sure the requested version is installed in the _work\tools folder.

Problem is that after that the highest available version is picked up. On almost all agents in our pool this is now 6.0.
The projects are not meant to be build with 6.0. For puild that is not a problem, but on publish the task fails with " error NETSDK1152: Found multiple publish output files with the same relative path". The error is because of a breaking change that was introduced with 6.0 .

We are failing to enforce version 3.1 or 5.0 for the publish step.

Task logs

2021-12-06T12:40:55.0033158Z ##[section]Starting: Use .NET Core sdk 3.1.100 2021-12-06T12:40:55.0257291Z ============================================================================== 2021-12-06T12:40:55.0257683Z Task : Use .NET Core 2021-12-06T12:40:55.0258139Z Description : Acquires a specific version of the .NET Core SDK from the internet or the local cache and adds it to the PATH. Use this task to change the version of .NET Core used in subsequent tasks. Additionally provides proxy support. 2021-12-06T12:40:55.0258556Z Version : 2.195.0 2021-12-06T12:40:55.0258755Z Author : Microsoft Corporation 2021-12-06T12:40:55.0258960Z Help : https://aka.ms/AA4xgy0 2021-12-06T12:40:55.0259194Z ============================================================================== 2021-12-06T12:40:55.3799912Z Tool to install: .NET Core sdk version 3.1.100. 2021-12-06T12:40:58.1895476Z Found version 3.1.100 in channel 3.1 for user specified version spec: 3.1.100 2021-12-06T12:40:58.2340128Z Version: 3.1.100 was found in cache. 2021-12-06T12:40:58.2348659Z Creating global tool path and pre-pending to PATH. 2021-12-06T12:40:58.2371081Z ##[section]Finishing: Use .NET Core sdk 3.1.100

Troubleshooting

I trying uninstalling the .net 6.0 that comes with the VS Build tools installed on the agents, but as people can use the task to install 6.0 in the agent work folder, I cannot completely remove the version from the agent.

I've found a workaround. With a PowerShell script I create a temporary global.json file in the '$(System.DefaultWorkingDirectory)' using dotnet new globaljson --sdk-version 3.1.100 --force

But we have 10+ projects and now I have to add this to every pipeline.

Error logs

Determining projects to restore...
  All projects are up-to-date for restore.
  MiscProj.Common.Core -> C:\agent\_work\563\s\MiscProj.Common\MiscProj.Common.Core\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Common.Core.dll
  MiscProj.Common -> C:\agent\_work\563\s\MiscProj.Common\MiscProj.Common\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Common.dll
  MiscProj.Common.Repositories.SqlServer -> C:\agent\_work\563\s\MiscProj.Common\MiscProj.Common.Repositories.SqlServer\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Common.Repositories.SqlServer.dll
  MiscProj.Common.Repositories.CosmosDb -> C:\agent\_work\563\s\MiscProj.Common\MiscProj.Common.Repositories.CosmosDb\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Common.Repositories.CosmosDb.dll
  MiscProj.Domain.Core -> C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Core\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Domain.Core.dll
  MiscProj.Common.Managers -> C:\agent\_work\563\s\MiscProj.Common\MiscProj.Common.Managers\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Common.Managers.dll
  MiscProj.Domain.Repositories.CosmosDb -> C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Repositories.CosmosDb\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Domain.Repositories.CosmosDb.dll
  MiscProj.Common.Messaging -> C:\agent\_work\563\s\MiscProj.Common\MiscProj.Common.Messaging\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Common.Messaging.dll
  MiscProj.Domain.Infrastructure.AzureCognitiveSearch -> C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Infrastructure.AzureCognitiveSearch\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Domain.Infrastructure.AzureCognitiveSearch.dll
  MiscProj.Domain.Infrastructure.SqlServer -> C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Infrastructure.SqlServer\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Domain.Infrastructure.SqlServer.dll
  MiscProj.Domain.Services -> C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Services\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Domain.Services.dll
  MiscProj.Common.Api -> C:\agent\_work\563\s\MiscProj.Common\MiscProj.Common.API\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Common.Api.dll
  MiscProj.Domain.Common -> C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Common\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Domain.Common.dll
  MiscProj.Domain.Managers -> C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Managers\bin\$(BuildConfiguration)\netcoreapp3.1\MiscProj.Domain.Managers.dll
C:\agent\_work\_tool\dotnet\sdk\6.0.100\Roslyn\Microsoft.CSharp.Core.targets(75,5): warning MSB3052: The parameter to the compiler is invalid, '/define:$(BUILDCONFIGURATION)' will be ignored. [C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Functions\MiscProj.Domain.Functions.csproj]
  MiscProj.Domain.Functions -> C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Functions\bin\$(BuildConfiguration)\netcoreapp3.1\bin\MiscProj.Domain.Functions.dll
C:\agent\_work\_tool\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: C:\Users\BuildAgentService\.nuget\packages\microsoft.azure.cosmos.direct\3.14.0\runtimes\win-x64\native\Microsoft.Azure.Cosmos.ServiceInterop.dll, C:\Users\BuildAgentService\.nuget\packages\microsoft.azure.cosmos\3.14.0\runtimes\win-x64\native\Microsoft.Azure.Cosmos.ServiceInterop.dll, C:\Users\BuildAgentService\.nuget\packages\microsoft.azure.cosmos.direct\3.14.0\runtimes\win-x64\native\Cosmos.CRTCompat.dll, C:\Users\BuildAgentService\.nuget\packages\microsoft.azure.cosmos\3.14.0\runtimes\win-x64\native\Cosmos.CRTCompat.dll. [C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Functions\MiscProj.Domain.Functions.csproj]
##[error]Error: The process 'C:\agent\_work\_tool\dotnet\dotnet.exe' failed with exit code 1
##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.API\MiscProj.Domain.API.csproj,C:\agent\_work\563\s\MiscProj.Domain\MiscProj.Domain.Functions\MiscProj.Domain.Functions.csproj
Finishing: dotnet publish
Apholisha commented 2 years ago

Hello, Any progress on this? Thanks.

rigardbester commented 2 years ago

Hi,

I started seeing this on my builds since this morning. Have multiple .Net 3.1 applications, build pipeline specifies TargetFramework : 'netcoreapp3.1', but get this same error /usr/share/dotnet/sdk/6.0.101/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: <list of random project appsettings.json and appsettings.Development.json files>

I worked around it by adding ErrorOnDuplicatePublishOutputFiles property to each of my projects, even though this is a property introduced in .Net 6 (https://docs.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#erroronduplicatepublishoutputfiles)

<PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
    <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
  </PropertyGroup>

Build succeeded after this

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

calebcartwright commented 2 years ago

Stay fresh please bot

akamud commented 1 year ago

I'm also having this issue in my cloud-hosted agents.
Incredible how such an issue is completely ignored with no word from the team.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

akamud commented 1 year ago

Not stale.

jacobhanson1010 commented 1 year ago

I just encountered this issue when trying to redeploy my freshly broken Blazor app. UseDotNet@2 had installed 7.0.302 (many regressions). So I specified 7.0.203 in UseDotNet, but VSBuild@1 still builds with 7.0.302. I had to delete 302 from C:\agent\_work\_tool\dotnet\sdk on my agent machine.

Addendum: My global.json was not set up correctly. I was allowing rollForward versions to latestMajor, which caused VSBuild@1 to use the latest installed patch (which was installed previously by UseDotNet@2). Regardless, the description of UseDotNet@2 stating that it enforces the version used "in subsequent tasks" is misleading since the global.json has final say.

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days