Repro
I have created my FIRST nuget package. Package project targets net standard 2.0.
It is built and published by azure pipeline:
...
- task: VSBuild#1
...
- task: VSTest#2
...
- task: NuGetCommand#2
inputs:
command: pack
packDestination: '$(Build.ArtifactStagingDirectory)/Nuget/MyPackage'
packagesToPack: '**/MyPackage.EventBus.nuspec'
- task: NuGetCommand#2
displayName: 'NuGet push'
inputs:
command: push
packagesToPush: '$(Build.ArtifactStagingDirectory)/Nuget/MyPackage/*.nupkg'
publishVstsFeed: 'MyFeed'
allowPackageConflicts: true
I have a nuspec file which has defined id, version, title, owner, license etc. and of course files:
<file src="MyPackage.EventBus\Factory\**" target="content\Factory" />
<file src="MyPackage.EventBus\Interfaces\**" target="content\Interfaces" />
<file src="MyPackage.EventBus\Null\**" target="content\Null" />
<file src="MyPackage.EventBus\ServiceBus\**" target="content\ServiceBus" />
<file src="MyPackage.EventBus\*.cs" target="content" />
<file src="MyPackage.EventBus\MyPackage.EventBus.csproj" target="content" />
Next I have installed my package in azure function v3 project with net core 3.1.
Problem
After installation I cannot reference any class or namespace from my package e.g.:
namespace MyPackage.EventBus
{
public abstract class BaseEvent
Tried
I have checked my nuget package file in NuGet Package Explorer:
It seems that there is no dll file. Should it be there in package or not? What to do to contain dll file in package if it is neccessary?
Related
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
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.
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.
I'm using Azure Dev Ops to work with my ASP.NET Core web application. I'm setting up a pipeline but I'm getting errors. The errors are coming from a package restore issue since my application uses the KendoUI library I have to create a service connection for the private NuGet packages that are required. Having done that, the build still fails and I was wondering what is going wrong?
Error Message
[error]The nuget command failed with exit code(1) and error(NU1102: Unable to find package Telerik.UI.for.AspNet.Core with version (>=
2019.2.619)
- Found 1 version(s) in NuGetOrg [ Nearest version: 2016.3.914 ] Errors in d:\a\1\s\MyCompany\MyProject.UI.csproj
NU1102: Unable to find package Telerik.UI.for.AspNet.Core with version (>= 2019.2.619)
- Found 1 version(s) in NuGetOrg [ Nearest version: 2016.3.914 ])
[error]Packages failed to restore
I spoke with Telerik support who said the above code is because there is a failure in authentication and that causes the system to look for an older version which is causing this compatibility issue. I was asked to check my authentication which I have, yet this error persists.
I followed the documentation from Telerik on how to achieve this which you can find here: https://www.telerik.com/blogs/azure-devops-and-telerik-nuget-packages
Ok, to start off, my project has a nuget.config file located in its root directory. The contents of the file are:
nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="Telerik" value="https://nuget.telerik.com/nuget" />
</packageSources>
<packageSourceCredentials>
<Telerik>
<add key="Username" value="me#mybusiness.com" />
<add key="ClearTextPassword" value="MyFunkYPassword19!" />
</Telerik>
</packageSourceCredentials>
</configuration>
Within Azure Dev Ops, I have created a service connection in the manner described in their documentation which has the name username and password as the above code
In my pipeline, I have added the Nuget package which is set to restore using my service connection above.
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: 'MyProject/nuget.config'
externalFeedCredentials: 'Telerik NuGet'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
The settings for the above pipeline step are as follows:
Does anyone have any ideas what's going on, is my setup incorrect?
I managed to get this working by accident. It was the order of the steps that was causing the problem. The output of the build showed that no matter what I did the pipeline was looking at a tempNuget.config file and not the one I had specified. Since there are two NuGet steps in the job I moved the Telerik up by one level and this ensured the system used the correct nuget.config file instead of looking at a temp one it was creating.
Here are the altered steps that caused it to start working, please note the Telerik step has been moved up by one step.
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: 'MyProject/nuget.config'
externalFeedCredentials: 'Telerik NuGet'
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
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.