I’ve never touched C# or .NET development before but was thrown into it for a hobby project two days ago, so please bear with my ignorance.
I am updating a .net project from framework version 2 to 5 using microsoft.net.sdk (ver. 8.0.300 [/snap/dotnet-sdk/245/sdk] installed via snap on Ubuntu 22.04)
I also running an azure pipeline to build my code and the agent I use is windows-2019
I can restore the project successfully, but not build.
When building I get an error requiring me to use framework Microsoft.NETCore.App version 3.1.0
even though I specify framework to be net5.0
. This prompted me to think one of my packages required that framework so I went through my package list on the .nuget website, but everything looks to be compatible with net5.0.
What am I missing here – any input will be greatly appreciated.
The Error message is:
<code> CyroinvestPublicAPI -> D:a1sbinDebugnet5.0CyroinvestPublicAPI.dll
Determining projects to restore...
Restored C:UsersVssAdministratorAppDataLocalTempojp42vr4.spjWorkerExtensions.csproj (in 8.68 sec).
WorkerExtensions -> C:UsersVssAdministratorAppDataLocalTempojp42vr4.spjbuildoutMicrosoft.Azure.Functions.Worker.Extensions.dll
##[error]C:UsersVssAdministrator.nugetpackagesmicrosoft.net.sdk.functions3.0.11buildMicrosoft.NET.Sdk.Functions.Build.targets(32,5): Error : It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
- The following frameworks were found:
5.0.17 at [C:hostedtoolcachewindowsdotnetsharedMicrosoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=3.1.0&arch=x64&rid=win10-x64
<code> CyroinvestPublicAPI -> D:a1sbinDebugnet5.0CyroinvestPublicAPI.dll
Determining projects to restore...
Restored C:UsersVssAdministratorAppDataLocalTempojp42vr4.spjWorkerExtensions.csproj (in 8.68 sec).
WorkerExtensions -> C:UsersVssAdministratorAppDataLocalTempojp42vr4.spjbuildoutMicrosoft.Azure.Functions.Worker.Extensions.dll
##[error]C:UsersVssAdministrator.nugetpackagesmicrosoft.net.sdk.functions3.0.11buildMicrosoft.NET.Sdk.Functions.Build.targets(32,5): Error : It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
- The following frameworks were found:
5.0.17 at [C:hostedtoolcachewindowsdotnetsharedMicrosoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=3.1.0&arch=x64&rid=win10-x64
</code>
CyroinvestPublicAPI -> D:a1sbinDebugnet5.0CyroinvestPublicAPI.dll
Determining projects to restore...
Restored C:UsersVssAdministratorAppDataLocalTempojp42vr4.spjWorkerExtensions.csproj (in 8.68 sec).
WorkerExtensions -> C:UsersVssAdministratorAppDataLocalTempojp42vr4.spjbuildoutMicrosoft.Azure.Functions.Worker.Extensions.dll
##[error]C:UsersVssAdministrator.nugetpackagesmicrosoft.net.sdk.functions3.0.11buildMicrosoft.NET.Sdk.Functions.Build.targets(32,5): Error : It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
- The following frameworks were found:
5.0.17 at [C:hostedtoolcachewindowsdotnetsharedMicrosoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=3.1.0&arch=x64&rid=win10-x64
and my csproj file looks like this:
<code><!--Project Sdk="Microsoft.NET.Sdk.Web"-->
<Project Sdk="Microsoft.NET.Sdk">
<TargetFramework>net5.0</TargetFramework>
<AzureFunctionsVersion>v8</AzureFunctionsVersion>
<FunctionsEnableWorkerIndexing>true</FunctionsEnableWorkerIndexing>
<SelfContained>true</SelfContained>
<!--TargetFramework>netcoreapp5</TargetFramework-->
<!--AzureFunctionsVersion>v2</AzureFunctionsVersion-->
<PackageReference Include="Azure.Identity"/>
<PackageReference Include="Azure.Security.KeyVault.Secrets"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk"/> <!--.NETFramework 4.7.2-->
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http"/>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5"/>
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication"/>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.27"/>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http"/>
<!--PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http"/-->
<!--PackageReference Include="Microsoft.NET.Sdk.Functions"/-->
<PackageReference Include="npgsql"/>
<PackageReference Include="SendGrid" Version="9.12.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" />
<PackageReference Include="Microsoft.Azure.Cosmos" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
<code><!--Project Sdk="Microsoft.NET.Sdk.Web"-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AzureFunctionsVersion>v8</AzureFunctionsVersion>
<FunctionsEnableWorkerIndexing>true</FunctionsEnableWorkerIndexing>
<SelfContained>true</SelfContained>
<!--TargetFramework>netcoreapp5</TargetFramework-->
<!--AzureFunctionsVersion>v2</AzureFunctionsVersion-->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity"/>
<PackageReference Include="Azure.Security.KeyVault.Secrets"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk"/> <!--.NETFramework 4.7.2-->
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http"/>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5"/>
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication"/>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.27"/>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http"/>
<!--PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http"/-->
<!--PackageReference Include="Microsoft.NET.Sdk.Functions"/-->
<PackageReference Include="npgsql"/>
<PackageReference Include="SendGrid" Version="9.12.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" />
<PackageReference Include="Microsoft.Azure.Cosmos" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
</code>
<!--Project Sdk="Microsoft.NET.Sdk.Web"-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AzureFunctionsVersion>v8</AzureFunctionsVersion>
<FunctionsEnableWorkerIndexing>true</FunctionsEnableWorkerIndexing>
<SelfContained>true</SelfContained>
<!--TargetFramework>netcoreapp5</TargetFramework-->
<!--AzureFunctionsVersion>v2</AzureFunctionsVersion-->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity"/>
<PackageReference Include="Azure.Security.KeyVault.Secrets"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk"/> <!--.NETFramework 4.7.2-->
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http"/>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5"/>
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication"/>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.27"/>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http"/>
<!--PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http"/-->
<!--PackageReference Include="Microsoft.NET.Sdk.Functions"/-->
<PackageReference Include="npgsql"/>
<PackageReference Include="SendGrid" Version="9.12.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" />
<PackageReference Include="Microsoft.Azure.Cosmos" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
And finally my azure-pipelines.yaml file is:
<code># https://aka.ms/yaml
displayName: 'Install .Net SDK 5.0.x'
displayName: 'Display .NET Info'
displayName: 'dotnet restore'
verbosityRestore: Detailed
displayName: 'dotnet build'
verbosityRestore: Detailed
displayName: 'dotnet publish'
publishWebProjects: false
arguments: '--no-restore --configuration Release --output $(Build.ArtifactStagingDirectory)'
verbosityRestore: Detailed
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
<code># https://aka.ms/yaml
trigger:
- master
- update_5_x_x
pool:
vmImage: windows-2019
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '5.0.x'
displayName: 'Install .Net SDK 5.0.x'
- script: |
dotnet --info
dotnet --list-sdks
displayName: 'Display .NET Info'
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/*.csproj'
verbosityRestore: Detailed
verbosityPack: Detailed
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
projects: '**/*.csproj'
verbosityRestore: Detailed
verbosityPack: Detailed
- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: publish
publishWebProjects: false
projects: '**/*.csproj'
arguments: '--no-restore --configuration Release --output $(Build.ArtifactStagingDirectory)'
verbosityRestore: Detailed
verbosityPack: Detailed
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
</code>
# https://aka.ms/yaml
trigger:
- master
- update_5_x_x
pool:
vmImage: windows-2019
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '5.0.x'
displayName: 'Install .Net SDK 5.0.x'
- script: |
dotnet --info
dotnet --list-sdks
displayName: 'Display .NET Info'
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/*.csproj'
verbosityRestore: Detailed
verbosityPack: Detailed
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
projects: '**/*.csproj'
verbosityRestore: Detailed
verbosityPack: Detailed
- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: publish
publishWebProjects: false
projects: '**/*.csproj'
arguments: '--no-restore --configuration Release --output $(Build.ArtifactStagingDirectory)'
verbosityRestore: Detailed
verbosityPack: Detailed
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
I can restore the project successfully, but when building I get the following error requiring me to use framework Microsoft.NETCore.App even though I specify framework to be net5.0. This prompted me to think one of my packages required that framework so I went through my package list on the .nuget website, but everything looks to be compatible with net5.0.
I have tried different combinations of versions of packages to no avail.
Again: I am very likely overlooking something basic here – any input will be much appreciated!