Autorest generates Client Sdk that needs a beta package - azure

I use Autorest to generate a Client Sdk for an Azure Function.
After that the Client Sdk should be packed and pushed to our nuGet feed.
These steps will all be done with a yaml pipeline for Azure DevOps.
This works really good for the last months. But recently Autorest has stopped working as usual.
Unfortunately autorest generates a project file that needs a beta nuGet package.
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" Version="3.0.0-beta.20210205.2" />
Of course, nuGet pack is not able to pack a project with beta or pre-release dependencies.
Does anyone have the same issue with autorest?
Can i configure autorest, not to use beta packages?
The generated project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>annotations</Nullable>
</PropertyGroup>
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<IncludeGeneratorSharedCode>true</IncludeGeneratorSharedCode>
<RestoreAdditionalProjectSources>https://azuresdkartifacts.blob.core.windows.net/azure-sdk-tools/index.json</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" Version="3.0.0-beta.20210205.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.6.0" />
</ItemGroup>
</Project>
The Pipeline that generates, packs and push the Client Sdk looks like that:
steps:
- powershell: 'npm install -g autorest#latest'
displayName: "Install AutoRest"
- task: AzurePowerShell#4
displayName: "Download Swagger"
inputs:
azureSubscription: ${{parameters.subscription}}
scriptType: 'InlineScript'
azurePowerShellVersion: 'LatestVersion'
inline: |
$context = New-AzApiManagementContext -ResourceGroupName "${{parameters.apimResourceGroup}}" -ServiceName "${{parameters.apim}}"
Export-AzApiManagementApi -Context $context -ApiId "$(appName)-development" -SpecificationFormat OpenApi -SaveAs "$(Build.ArtifactStagingDirectory)\definition-$(version).yaml"
- powershell: 'autorest --verbose --v3 --csharp --add-credentials --input-file="$(Build.ArtifactStagingDirectory)\definition-$(version).yaml" --output-folder="$(Build.Repository.LocalPath)\Api\src\ClientSdk" --namespace="ClientSdk" --override-client-name="Client"'
displayName: 'Run AutoRest'
- task: DotNetCoreCLI#2
displayName: "Pack Projects"
inputs:
command: "pack"
arguments: "--configuration $(buildConfiguration) --include-symbols"
packagesToPack: "**/ClientSdk.csproj"
versioningScheme: "off"
verbosityPack: "Normal"
- task: DotNetCoreCLI#2
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/**/*.nupkg;!$(Pipeline.Workspace)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: ${{parameters.nugetfeed}}
The nuGet pack task failes with this error
1>C:\Program Files\dotnet\sdk\5.0.102\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(207,5): error NU5104: A stable release of a package should not have a prerelease dependency. Either modify the version spec of dependency "Microsoft.Azure.AutoRest.CSharp [3.0.0-beta.20210205.2, )" or update the version field in the nuspec.

Using a pre-release package in a release package is unstable and dangerous. This error is there to prevent this from happening. There are a couple options you can employ:
Mark your package as pre-release
Assuming your project is still in development and needs to utilize this latest dependency that's still in development, simply mark your package as in development as well. From the Microsoft docs:
If your project uses PackageReference: include the semantic version
suffix in the .csproj file's PackageVersion element:
<PropertyGroup>
<PackageVersion>1.0.1-alpha</PackageVersion>
</PropertyGroup>
If your project has a packages.config file: include the semantic
version suffix in the .nuspec file's version element:
<version>1.0.1-alpha</version>
Use the last stable build
Fall back to the last version of your dependencies that use release packages. This is generally safer, as in-development dependencies may introduce serious issues that are yet unknown. If the project developers believed their project to be safe for production use they would mark it as such.

Related

Telerik Nuget package restore in Azure build pipeline fails

I'm attempting to pull Nuget packages from Telerik's Nuget repository into an Azure build pipeline, however, none of the pipeline configuration attempts I've made seem to work. I either receive an error stating my nuget.config is not formatted correctly or a 401 error when connecting to the repository.
The below configuration section is from my build definition. I've tried using NuGetCommand as well as NuGetRestore:
- task: NuGetToolInstaller#1
inputs:
versionSpec: '5.0.2'
- task: NuGetAuthenticate#1
inputs:
nuGetServiceConnections: 'Telerik_v3'
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: './XXXXXXX/nuget.config'
#'$(System.DefaultWorkingDirectory)/XXXXXXX/NuGet.config'
externalFeedCredentials: 'Telerik_v3'
# - task: NuGetRestore#1
# inputs:
# solution: '**/*.sln'
# selectOrConfig: 'config'
# nugetConfigPath: './XXXXXXX/nuget.config'
Here is my nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
<add key="Telerik_NuGet" value="https://nuget.telerik.com/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
Here is the error I receive:
NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://nuget.telerik.com/v3/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
Tweaking the configuration slightly I get this error:
##[error]The nuget command failed with exit code(1) and error(NuGet.Configuration.NuGetConfigurationException: NuGet.Config is not valid XML. Path: 'D:\a\1\Nuget\tempNuGet_966.config'. ---> System.Xml.XmlException: An error occurred while parsing EntityName. Line 10, position 46.
I based my build tasks on the NuGetCommandv2 and NuGetRestore v1 documentation as well as what I found on Telerik's site.
When we want to use private nuget packages like Telerik we need to specify credentials in Nuget.config_
Connection name
Feed URL
Username
Password
NOTE:
In order to add a reference to this NuGet package to your project, firstly need to add Telerik credentials into Visual Studio.
example:
dotnet nuget update source "Telerik" --source "https://nuget.telerik.com/v3/index.json" --configfile "nuget.config" --username '*************' --password '***********' --store-password-in-clear-text
Here I found one reference github by Lance McCarthy

Azure build pipeline unable to restore NuGet packages from private feed when using NuGet.Config file from solution

I am trying to build a C# project in DevOps build pipeline. The project is using a single Azure Artifacts private feed. The NuGet.config is as given by the Azure portal from the Nuget tab of connect feed page. The file is at the root of the solution.
NuGet.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositorypath" value=".\packages" />
<packageSources>
<clear />
<add key="<myfeedname>" value="https://pkgs.dev.azure.com/<myorg>/<myproject>/_packaging/<myfeedname>/nuget/v3/index.json" />
</packageSources>
</config>
</configuration>
I am having difficulty restoring packages when using NuGet.config from the solution. The log shows some evidence of using the azure org related URLs but not the project or feed. The restore cannot find packages. However, if I specify the feed and package folder in the NuGet restore task itself, it works fine and downloads all packages. I am expecting the task to find the private feed URL automatically from the NuGet.config file, authenticate (since inside pipeline), and download packages. The config file works fine in local builds asking for org user credentials (pop up) when using VS. The NuGet.config is checked into repo and hence there are no credentials used.
I also have NuGet Authenticate task just in case. (The working version doesn't even need this task).
- task: NuGetAuthenticate#0
What is wrong with the non-working version?
Working Version:
- task: NuGetCommand#2
displayName: "Step: Restore NuGet"
inputs:
command: 'restore'
feedsToUse: 'select'
vstsFeed: '<myproject>/<MyFeed>'
includeNuGetOrg: false
restoreSolution: '$(solution)'
restoreDirectory: "../../packages"
verbosityRestore: Detailed
continueOnError: true
Non-Working Version:
- task: NuGetCommand#2
displayName: "Step: Restore NuGet"
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'config'
nugetConfigPath: "NuGet.config"
verbosityRestore: Detailed
continueOnError: true
From non-working version, the log shows that it is using the file as expected.
C:\hostedtoolcache\windows\NuGet\5.8.1\x64\nuget.exe restore D:\a\1\s\<solution-file-path> -Verbosity Detailed -NonInteractive -ConfigFile D:\a\1\s\NuGet.config
NuGet Version: 5.8.1.7021
Some errors:
WARNING: Unable to find version '6.0.0' of package 'Microsoft.CodeAnalysis.NetAnalyzers'.
NU1100: Unable to resolve 'AsyncFixer (>= 1.5.1)' for '.NETFramework,Version=v4.8'.
I also find some logs related to devops org for auth but no mention of project or feed name,
##[debug]Discovered URL prefixes: https://dev.azure.com/<my-org>/,.....others....
:
##[debug]Got auth token
..
:
##[error]Packages failed to restore
No mention of NuGet sources used in log. (System.Debug set to true in variables)
The working version shows the private feed as source used at the end.
NuGet Config files used:
D:\a\1\Nuget\tempNuGet_2852.config
Feeds used:
https://pkgs.dev.azure.com/<org>/<proj>/_packaging/<feed>/nuget/v3/index.json
However, I want to use the config version since it seems to be the right approach.

Why is msbuild.exe missing in C:\Program Files\dotnet\sdk\3.1.201? Causing AzureDevOps build step to fail

I have a very simple WPF project (.Net 4.7.2) and Unit Test project (MSTest .Net Core) and I'm trying to get it to build in Azure Pipelines and I'm getting following error:
2020-05-07T16:41:52.9562570Z C:\Program
Files\dotnet\sdk\3.1.201\Microsoft.Common.CurrentVersion.targets(3032,5):
error MSB4216: Could not run the "GenerateResource" task because
MSBuild could not create or connect to a task host with runtime "CLR4"
and architecture "x86". Please ensure that (1) the requested runtime
and/or architecture are available on the machine, and (2) that the
required executable "C:\Program Files\dotnet\sdk\3.1.201\MSBuild.exe"
exists and can be run.
[C:\agent_work\4\s\RsSolution4\WpfApp1\WpfApp1.csproj]
2020-05-07T16:41:53.1174401Z ##[error]Error: The process 'C:\Program
Files\dotnet\dotnet.exe' failed with exit code 1
I looked for msbuild.exe in suggested folder and sure enough it doesn't exist. The path exists and there are many files in folder, just not msbuild.exe. There's an msbuild.dll.
Here's my yaml file:
trigger:
- master
pool:
name: Default
demands: msbuild
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI#2
displayName: Restore NuGet
inputs:
command: 'custom'
projects: '**/*.csproj'
custom: 'restore'
- task: MSBuild#1
inputs:
solution: '**/*.sln'
msbuildLocationMethod: 'location'
msbuildLocation: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\msbuild.exe'
configuration: 'Release'
clean: true
- task: DotNetCoreCLI#2
displayName: SSP Automated Testing
inputs:
command: 'test'
projects: '**/*Test*.csproj'
arguments: '--configuration $(buildConfiguration)'
testRunTitle: 'SSP Testing'
It seems like this known issue for dotnet core. It said On .NET Core, MSBuild doesn't support task hosts of different architectures/runtime versions.
The workaround provided is to add CurrentArchitecture/CurrentRuntime to PropertyGroup. See this similar issue.
<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Core' Or '$(TargetFrameworkIdentifier)' != '.NETFramework'">
<GenerateResourceMSBuildArchitecture Condition=" '$(GenerateResourceMSBuildArchitecture)' == '' ">CurrentArchitecture</GenerateResourceMSBuildArchitecture>
<GenerateResourceMSBuildRuntime Condition=" '$(GenerateResourceMSBuildRuntime)' == '' ">CurrentRuntime</GenerateResourceMSBuildRuntime>
</PropertyGroup>
You also try using msbuild task only to build all your projects, for msbuild works for both .net framework and .net core. You can specify solutions and projects for the solution parameter of Msbuild task.
Since there are .Net framework projects and .Net Core projects in your solution. I would suggest using Nuget restore task to restore the solution. Dotnet cli doesnot works properly with .NET Framework, which wil probably fail to restore the .net framework projects.
Hope above helps!
make sure you add a UseDotNet task to ensure the correct version of the SDK is available on the agent:
- task: UseDotNet#2
inputs:
packageType: 'sdk'
version: '3.1.201'
And I'd opt to use the dotnet build task to build the .NET Core project and the VisualStudioBuild task for the WPF project, that way you're not intermingling framework types and SDKs in then same solution build.

Deploying .NET Core 3.0 API to Azure Web App using Release Pipeline

I'm attempting to upgrade my API from .NET Core 2.2 to 3.0, but I cannot get the Azure Web App to actually run the application using 3.0.
My build pipeline configuration:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core 3'
inputs:
version: 3.x
- script: dotnet tool install --global dotnet-ef
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: efcore-migration-script-generator-task#0
inputs:
projectpath: 'Models/Models.csproj'
databasecontexts: 'DataContext'
startupprojectpath: 'Api/Api.csproj'
targetfolder: '$(build.artifactstagingdirectory)/migrations'
- script: dotnet publish --output $(Build.ArtifactStagingDirectory)
displayName: 'dotnet publish $(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
I then have a multi-stage release pipeline that publishes the artifact to Azure using the Azure App Service Deploy Task. Everything runs without issue
I've installed the preview extension, as directed here, and running the powershell command Test-Path D:\home\SiteExtensions\AspNetCoreRuntime.3.0.x86\ returns true. I'm still seeing the following error though.
ANCM Failed to Find Native Dependencies
Back in Powershell, running dotnet --version and dotnet --list-runtimes shows that it only recognizes .NET Core 2 runtimes, despite the 3.0 runtime being present. As best I can tell, installing the site extension doesn't update the path to use the new dotnet version, and the Azure Devops deploy task doesn't seem to have any options to override the default. Has anyone managed to get a .NET Core 3 app deployed through Azure Devops Release Pipelines?
I don't consider it a good solution by any means, but the workaround I'm using right now that is working is to add a web.config file that passes the full path to the site extension version of dotnet
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="D:\home\SiteExtensions\AspNetCoreRuntime.3.0.x86\dotnet" arguments=".\Api.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
I'm still looking for a solution that isn't so error prone.

Autofac cannot be found in release pipeline

I have a program MyProgram.csproj (which happens to be a .NET Core console app) and I am copying it's build (bin\netcoreapp2.2) into the release pipeline and trying to run it MyProgram.dll through Powershell as a task.
When I do so I get the error
2019-08-14T01:35:58.1153997Z An assembly specified in the application dependencies manifest (MyProgram.deps.json) was not found:
2019-08-14T01:35:58.1154837Z package: 'Autofac', version: '4.2.1'
2019-08-14T01:35:58.1155904Z path: 'lib/netstandard1.1/Autofac.dll'
The reference is
"Autofac/4.2.1": {
"dependencies": {
"System.ComponentModel": "4.0.1"
},
"runtime": {
"lib/netstandard1.1/Autofac.dll": {
"assemblyVersion": "4.2.1.0",
"fileVersion": "4.2.1.0"
}
}
}
Any way I can get more information about why this assembly cannot be found?
Can you try adding the following to my .csproj:
<PropertyGroup>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
and try updating all the references on the project
The better way to get rid of dependency chaos is to deploy a self-contained publish, so that includes .NET Core libraries, the .NET Core runtime and referenced package dependencies.
Following this link, you can determine the runtime identifier (e.g. win-x64) and the configuration settings for release or debug builds.
dotnet publish .\MyProgram.csproj -c Release -r "win-x64" --self-contained -o .\publish
You can either use the dotnet extension in the build definition or add a powershell inline command to run the mention codes.
YAML Example
resources:
- repo: self
queue:
name: DefaultAgentPool
steps:
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
feedsToUse: config
nugetConfigPath: nuget.config
- powershell: |
# Write your powershell commands here.
Write-Host "Starting dotnet cli publish command ..."
dotnet publish --runtime "win-x64" -o $(Build.ArtifactStagingDirectory) -c Release --self-contained
workingDirectory: src/Project
displayName: 'dotnet publish'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: win'
inputs:
ArtifactName: win-publish
This makes you sure that you're not going to get any dependency error in the specified runtime platform.

Resources