Azure DevOps restore fails - c#

I added a nuget restore which works fine. Dev and Release build works fine on my pc.
Its failing in Azure Devops restore.
Link to error txt
Error.txt
My Csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.5</RuntimeFrameworkVersion>
<UserSecretsId>aspnet-AspNetCorePagesIdentity-***************-***-*******-</UserSecretsId>
<TypeScriptToolsVersion>3.0</TypeScriptToolsVersion>
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Content Include="Client\assets\control-logo.png" />
<Content Include="Client\assets\webrelay_170.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Folder Include="Areas\Identity\Services\" />
</ItemGroup>
<ItemGroup>
<Content Update="Client\_ViewImports.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
</ItemGroup>
</Project>

You need to use cmd line and use "dotnet restore" not build in nuget restore task.
in yaml
steps:
- task: DotNetCoreCLI#2
inputs:
command: restore
projects: '**/*.csproj'
feedsToUse: config
nugetConfigPath: NuGet.config # Relative to root of the repository
externalFeedCredentials: <Name of the NuGet service connection>

Related

Azure function v4 migration. Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral

I'm currently migrating an Azure Function from v2 to Azure Functions v4. I already migrated my project to .NET6 and fixed all the package reference errors. I have in the solution 3 projects which I adjusted to .NET6 and Azure Function v4. For that I edited the .csproj files of each of those projects and upgraded/substituted packages which are not working with .NET6. The project file of each project looks like:
Azure Function Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.5" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.18.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.33" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="5.1.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.48.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PCM.1.z\x.1.z.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="2.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
<Compile Update="1.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
<Compile Update="3.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Second Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.5" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.Devices" Version="1.38.2" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.33" />
<PackageReference Include="SendGrid" Version="9.28.1" />
<PackageReference Include="StackExchange.Redis" Version="2.6.80" />
<PackageReference Include="Twilio" Version="6.0.1" />
<PackageReference Include="UnitsNet" Version="4.149.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\x.1.w\x.1.w.csproj" />
</ItemGroup>
</Project>
Third Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
</ItemGroup>
</Project>
When I build the project I got no errors. But when I debug the project I got an exception which looks like:
Exception:
Exception thrown: 'System.IO.FileNotFoundException' in Microsoft.Azure.WebJobs.Host.dll.
An exception of type 'System.IO.FileNotFoundException' occurred in Microsoft.Azure.WebJobs.Host.dll but was not handled in user code
Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
I have tried the last two weeks different packages since when I googled this error, the suggestion was to see which packages are not supported by package:
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />. I analyzed all my packages. After changing them back and force I got still the same error.
Can anyone help me and say what exactly I have to change?
As #Codebrane said, Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0 has the issues in working with Azure Functions v4 Version and it has been shown practically in this thread.
Try by downgrading the Microsoft.Extensions.Configuration.Abstractions to Version 6.0.0 and check.
Microsoft.NET.Sdk.Functions depends on the NuGet Packages related to the Code but these can be suggested by VS IntelliSense and installed automatically, or it shows these packages required.
Also, NuGet Packages varies between In-Process and Out-of-Process worker type in Azure Functions. Refer to one of my threads for more information.
I am building an Azure function as v4 in net6. Since I also got the System.IO.FileNotFoundException regarding library Microsoft.Extensions.Configuration.Abstraction 7.0.0 when starting up the function,
I downgraded to Microsoft.Extensions.Configuration.Abstractions 6.0.0 and also had to downgrade other dependencies such as Microsoft.EntityFrameworkCore to 6.0.12 and, since I am using PostgreSQL also Npgsql.EntityFrameworkCore.PostgreSQL to 6.0.8. Now everything works.
I fixed it by including the package Microsoft.Extensions.Configuration.Abstractions 6.0.0 and building it. To include this package doesn't solve the problem directly it just shows which packages have a conflict. By downgrading these conflicting packages the project could be debugged. To check which packages are conflicting you have to open up the packages on the right side in visual studio and look where is a exclamation mark. Then you have to analyze these packages to know on what version you have to downgrade them. It changes from project to project.

Restoring dotnet tools found in csproj file. What does this mean for my project?

The csproj file of my newly created Android project in VS for Mac 2022 looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-android</TargetFramework>
<SupportedOSPlatformVersion>31</SupportedOSPlatformVersion>
<OutputType>Exe</OutputType>
<ApplicationId>com.companyname.TestProjectAndroid</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" />
<PackageReference Include="MonoGame.Framework.Android" Version="3.8.1.303" />
</ItemGroup>
<ItemGroup>
<None Remove="proguard.cfg" />
</ItemGroup>
<ItemGroup>
<ProguardConfiguration Include="proguard.cfg" />
</ItemGroup>
<Target Name="RestoreDotnetTools" BeforeTargets="Restore">
<Message Text="Restoring dotnet tools" Importance="High" />
<Exec Command="dotnet tool restore" />
</Target>
</Project>
At the end it has Restoring dotnet tools and Importance="High". What does this Restoring dotnet tools mean? Is something wrong with my project?
I use VS for Mac 2022 17.3.8 (build 5).

Multiple level nuget dependency c#

We're facing dificulties trying to make nuget install dependencies of dependencies. We publish custom nugets to an Azure Artifacts with more than one level of dependencies and nuget only installs the first level of these depencencies. As an example:
Nuget A has a dependency on Nuget B.
Nuget B has a dependency on Nuget C.
A, B and C are all nugets published in our azure artifacts.
Under this scenario, when we install nuget A in a solution it also installs nuget B (listed as a dependency), but nuget C is not installed (although it is necessary for B to work). Is there a way to accomplish this dependency hierarchy when installing a nuget?
All these nugets were published throughout a pipeline like this one:
parameters:
vmImage: 'windows-latest'
nugetFeed: '[Our_GUID_Feed]'
solution: ''
project: ''
BuildConfiguration: ''
jobs:
- job: Job
pool:
vmImage: '${{ parameters.vmImage }}'
steps:
- task: DotNetCoreCLI#2
displayName: 'Restore packages'
inputs:
command: 'restore'
projects: '${{ parameters.solution }}'
vstsFeed: '${{ parameters.nugetFeed }}'
env:
System_AccessToken: $(System.AccessToken)
- task: DotNetCoreCLI#2
displayName: 'Dotnet Build Project'
inputs:
arguments: '--configuration ${{ parameters.BuildConfiguration }} /p:Version=$(Build.BuildNumber) /p:Optimize=false --no-restore'
projects: '${{ parameters.project }}'
versioningScheme: byBuildNumber
- task: DotNetCoreCLI#2
displayName: 'Dotnet Package Project'
inputs:
command: pack
packagesToPack: '${{ parameters.project }}'
buildProperties: Version=$(Build.BuildNumber)
- task: DotNetCoreCLI#2
displayName: 'Dotnet Push Project'
inputs:
command: push
nuGetFeedType: 'internal'
publishVstsFeed: '${{ parameters.nugetFeed }}'
Edit:
Further info of the problem with an actual example:
This is the csproj of nuget C:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="9.3.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.10" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
</ItemGroup>
</Project>
Dependencies of C shown in vs
This is the csproj of the nuget B:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NugetC" Version="1.0.20" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.10" />
</ItemGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="#(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
</ItemGroup>
</Target>
</Project>
Dependencies of B shown in vs
This is the csproj of nuget A:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.78" />
<PackageReference Include="NugetB" Version="1.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.10" />
<PackageReference Include="Moq" Version="4.15.2" />
<PackageReference Include="NEST" Version="7.9.0" />
</ItemGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="#(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
</ItemGroup>
</Target>
</Project>
Dependencies of A shown in vs
As you can see in this last screenshot, C is not listed as a dependency of A when i try to install it.

How to fix version conflict for MicrosoftEntityFrameworkCore

I create a WEB API in .NET CORE with the 'dotnet new' command. i want to configure this with Entity Framework Core but i cant. I install this with the 'Manage Nugets Pakages' in VS2017 and VS give me a error.
I tried to restore packages but the error persist.
my csproj file:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CORE\CORE.csproj" />
<ProjectReference Include="..\DAL\DAL.csproj" />
<ProjectReference Include="..\DOORACCESS\DOORACCESS.csproj" />
<ProjectReference Include="..\DPFINGER\DPFINGER.csproj" />
<ProjectReference Include="..\LOGIC\LOGIC.csproj" />
<ProjectReference Include="..\utest\utest.csproj" />
</ItemGroup>
</Project>
As you can see download the packages but do not add them to the csproj. I tried to do it manually, but when I put it in, I was asking for its dependencies one by one.

Fresh installed Visual Studio NuGet package manager cannot import Microsoft.AspNetCore.All package

I'm trying to create an asp.net core 2.0 web api project with visual studio enterprise edition(fresh installed) and NuGet Package Manager fails at build phase of the project.
Here is the error message on visual studio
Result of dotnet restore
Any ideas about this problem?
.csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="DataTransObj" />
<Folder Include="Json" />
<Folder Include="LogDepot" />
<Folder Include="FileDepot\" />
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.7" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.10" />
<PackageReference Include="Serilog" Version="2.7.1-dev-00950" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="2.6.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.1-dev-00790" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
obj/...nuget.g.targets file :
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.0\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.0\build\netstandard2.0\NETStandard.Library.targets')" />
<Import Project="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\build\netcoreapp2.0\Microsoft.NETCore.App.targets" Condition="Exists('C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\build\netcoreapp2.0\Microsoft.NETCore.App.targets')" />
<Import Project="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.configuration.usersecrets\2.0.1\build\netstandard2.0\Microsoft.Extensions.Configuration.UserSecrets.targets" Condition="Exists('C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.configuration.usersecrets\2.0.1\build\netstandard2.0\Microsoft.Extensions.Configuration.UserSecrets.targets')" />
<Import Project="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.3\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets" Condition="Exists('C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.3\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets')" />
<Import Project="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.all\2.0.7\build\netcoreapp2.0\Microsoft.AspNetCore.All.targets" Condition="Exists('C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.all\2.0.7\build\netcoreapp2.0\Microsoft.AspNetCore.All.targets')" />
</ImportGroup>
</Project>
Fresh installed Visual Studio NuGet package manager cannot import Microsoft.AspNetCore.All package
The default asp.net core 2.0 web api project template contains some nuget packages, which will import some .targets file. According to the error message:
"The imported project file ...Microsoft.AspNetCore.All.targets, cold
not be loaded. Root element is missing"
It seems the imported .target file is damaged in the NuGetFallbackFolder folder. Since it is a fall back folder, to resolve this issue, you can delete this package in that folder. Then when you create a new project, you will find Visual Studio will load that package from global packages folder C:\Users\<UserName>\.nuget\packages. Or you can copy this package from global folder to the NuGetFallbackFolder.
Hope this helps.

Categories