Azure DevOps build pipline constantly giving version conflict on every package - asp.net-core

I have a simple .NET Core 2.2 website along with Microsoft.Identity.Web added as a .NET Core assembly. The following .csproj files make up my solution:
Main project:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<WebProject_DirectoryAccessLevelKey>1</WebProject_DirectoryAccessLevelKey>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.Graph" Version="1.14.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Identity.Web\Microsoft.Identity.Web.csproj" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>
</Project>
Microsoft.Identity.Web project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="2.2.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="3.0.6-preview" />
</ItemGroup>
</Project>
NOTE: I can build the solution locally without issue and have never had an issue with it building or running -ever.
I created a new Azure DevOps pipeline and pointed it at my Github repo. During the NuGetCommand process it fails telling me:
[error]The nuget command failed with exit code(1) and error(NU1607: Version conflict detected for Microsoft.AspNetCore.Antiforgery. Reference the package directly from the project to resolve this issue.
Based on this I thought I needed to install that package directly so I went to NuGet package manager, searched for the package, and installed it. Then I get a different error:
[error]The nuget command failed with exit code(1) and error(NU1607: Version conflict detected for Microsoft.AspNetCore.Authentication.Cookies. Reference the package directly from the project to resolve this issue.
Tried installing that package and I get another error:
[error]The nuget command failed with exit code(1) and error(NU1607: Version conflict detected for Microsoft.AspNetCore.Authorization.Policy. Reference the package directly from the project to resolve this issue.
..and so on and so on...
So installing these erroneous packages is not likely the right way forward so I also tried:
Changing my main .csproj file to use <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" /> but that just gave more of the same above errors (different ones) and according to Nate here we shouldn't be including explicit versions.
At one point after installing all these packages it seemed to be hung on the <PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="2.2.0" /> reference so following guidance from a colleague I changed that version to 2.1.0 but again, no resolution; just more red herrings.
I've been fighting with this for four days now and I'm completely lost on how to solve it. Any guidance would be appreciated.
Update:
Initially I had set up my DevOps build pipeline by following the 'wizard' steps within DevOps itself. I chose my repo and it selected my master branch automatically including setting up a yaml file. I ran the build as the last step in the wizard and that's where my problems started.
I thought I would take a different approach in troubleshooting by setting up my Azure resource group first, then my app service, dependent PaaS services, and finally configure the 'deployment options' section. I followed the steps there to choose Azure DevOps as my build/deploy pipeline, selected my organization, repo, and clicked finish. It set up the build and deploy without issue.
I'll leave this post here for suggestions and hopefully have a definitive answer to why it didn't work. I feel like the errors with my first approach were red herrings all together though...

Related

ANCM Out of Process in .Net Core 2.2 Web API Project --

My problem is as such -
I have a .NET core webapi project [targeting 2.2]. Now while trying to run it, I get the following error as shown in the image -
I consulted this link -->
HTTP Error 500.30 - ANCM In-Process Start Failure and
https://github.com/aspnet/AspNetCore/issues/8980
tried by editing the .csproj file. Tried downgrading to netcoreapp2.1. Downgrading the assembly versions. Did not work. SO reverted back again.
Changed to 'InProcess' and 'Everyone'. But that did not work either. The same error message shows.
My .csproj file right now:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>Everyone</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
</ItemGroup>
</Project>
Fact of the matter is I have .NET Core SDK and Runtimes upto version 3.1 installed on the environment. But still.
I have tried several perms/combs of changing settings and sdk etc for the project so far. But it is eluding me. What is exactly the problem? I have a hunch it is something minute but crucial and it is eluding me. If you need farther details about project version/settings pl do let know, will share.
Right now, this is my .csproj latest --
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>Everyone</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
</ItemGroup>
</Project>
Coincidentally or what I don't know, I seems to have stumbled upon the solution and the ideal settings myself and it is working now. Although I don't have the exact logical answer as to what and why, but yeah. The error is no more.
Thanks anyway,

Donet core Conflicts between different versions of "Microsoft.AspNetCore.Authentication.Abstractions"

I am currently working on major refactoring of project and in the process trying to remove all Warnings our code base had. Finally down to 11 Warnings, but can't really see what is going on with 9 of them, which all seem to be related. Something like:
Severity Code Description Project File Line Suppression State
Warning MSB3277 Found conflicts between different versions of
"Microsoft.AspNetCore.Authentication.Abstractions" that could not be
resolved. These reference conflicts are listed in the build log when
log verbosity is set to
detailed. #######.Test.Integration C:\Program Files
(x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2106
I have Consolidated the nuget package versions.
Checked the Csproj file and it seemed fine. (See below.)
All warnings are in Microsoft.AspNetCore.*
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FakeItEasy" Version="5.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\###\###API.csproj" />
<ProjectReference Include="..\###\###.Core.csproj" />
<ProjectReference Include="..\###\###.Data.csproj" />
</ItemGroup>
</Project>
Try to use the web SDK (Microsoft.NET.Sdk.Web instead of Microsoft.NET.Sdk) and add a package reference to Microsoft.AspNetCore.App without specifying a version
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>
Refer to Integration and unit tests no longer work on ASP.NET Core 2.1 failing to find assemblies at runtime
https://github.com/dotnet/sdk/issues/2253

Dotnet watcher - Illegal characters in path -- what could cause this error?

Can anyone help us understand why dotnet watch is causing our applications to crash?
I'm using dotnet new mvc and yo aspnetcore-spa to create apps in visual studio code. Both work fine until I try to add a reference to DotNet Watcher tools using example at https://github.com/aspnet/DotNetTools/tree/dev/src/Microsoft.DotNet.Watcher.Tools to insert reference in csproj file:
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup>
After adding to csproj and dotnet restore, the application throws an error and fails and is unrecoverable. It has to be deleted and I have to start from scratch.
Full csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>
netcoreapp1.1
</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup>
</Project>
The error thrown is below and happens no matter where we create the application on disk or what it is named.
C:\Program Files\dotnet\sdk\1.0.1\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets(90,5): error MSB4184: The expression "[System.IO.Path]::GetFullPath(C:\test\obj\Debug\ [C:\test\test.csproj]
C:\Program Files\dotnet\sdk\1.0.1\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets(90,5): error MSB4184: netcoreapp1.1 [C:\test\test.csproj]
C:\Program Files\dotnet\sdk\1.0.1\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets(90,5): error MSB4184: \PubTmp)" cannot be evaluated. Illegal characters in path. Parameter name: path [C:\test\test.csproj]
Our environment is:
.NET Command Line Tools (1.0.1)
Microsoft .NET Core Shared Framework
Host Version : 1.1.0
Build: 928f77c4bc3f49d892459992fb6e1d5542cb5e86
Visual Studio Code v 1.10.2
Windows 10
Problem solved. An extension named "XML Formatter" was rewriting the csproj file on save and adding hard returns and tabs. Removing this extension, restoring csproj to it's original state, adding back in the DotNetCliToolReference code block and rebuilding via dotnet restore solved the issue.

.NET Core how to test with net461 and xunit

dotnet new xunit ->
dotnet restore ->
dotnet test
Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 1,7148 Seconds.
.csproj; change target framework to net461:
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
</Project>
then
dotnet restore ->
dotnet test
Starting test execution, please wait...
No test is available in C:\Projects\testing\bin\Debug\net461\testing.dll. Make sure that installed test discoverers & executors, platform & framework version sett
ings are appropriate and try again.
How am I supposed to test net461-projects with xunit?
I already have a big project I've upgraded from .NET Core 1.0, and testing worked fine before the upgrade, so changing test framework would require some work.
Update
As it turns out, this is probably not related to xunit and testing - ASP.NET Core projects targeting net461 won't run at all on my machine anymore, neither through VS or from cmd.
The project I am trying to run is an new empty web project from the VS template. The csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
</ItemGroup>
</Project>
The error I get is this:
dotnet run
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Hosting, Version=1.1.1.0, Culture=neutral, PublicKeyTo
ken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
at WebApplication2.Program.Main(String[] args)
I have tried removing all traces of Visual Studio and .NET Core from my machine and reinstalling them, but the error is the same.
There is an issue with runtime identifier inference and how the test sdk works.
Try adding this to your <PropertyGroup> (assuming you're on a 64 bit windows):
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
you could also add
<OutputType>Exe</OutputType>
which would turn your class library project into an exe but this should work around the issue.
Yeah, I've experienced the same issue. Not sure if Microsoft already has a fix available, but it seems that some packages of ASP.NET Core 1.1.x are targeting NetStandard Library 1.6.1, which is not compatible with .NET Framework... See the matrix on MS website here: https://learn.microsoft.com/en-us/dotnet/articles/standard/library#net-platforms-support
We've decided to stick to ASP.NET Core 1.0.x for now.

How to copy files to output directory from a referenced NuGet package in .NET Core csproj?

I'm trying to use PhantomJS NuGet package in .NET core csproj application. But I think it is not possible using new PackageReference syntax for NuGet.
When I reference the PhantomJS package like this:
<PackageReference Include="PhantomJS" Version="2.1.1">
<IncludeAssets>all</IncludeAssets>
</PackageReference>
It does not do anything when I run dotnet build.
I'd expect it to copy the files inside PhantomJS package to the output directory (or anywhere in the project) so I could use the binary file provided by the PhantomJS package.
Is there another way to copy the contents of PhantomJS NuGet package to the output directory with MSBuild?
I think you want to use:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
in the main <PropertyGroup>, which causes all dependencies to be copied to the output folder. This means every single dependency gets copied though so this can be quite a mess in some situations.
If you then want to exclude specific assemblies or packages:
<ItemGroup>
<-- won't copy to output folder -->
<PackageReference Include="MahApps.Metro" version="1.6.5">
<IncludeAssets>compile</IncludeAssets>
</PackageReference>
<PackageReference Include="Dragablz" version="0.0.3.203">
<IncludeAssets>compile</IncludeAssets>
</PackageReference>
...
<-- normal will copy to output folder -->
<PackageReference Include="xmlrpcnet" version="3.0.0.266" />
<PackageReference Include="YamlDotNet" version="6.0.0" />
</ItemGroup>
<ItemGroup>
<!-- keep assembly reference from copying to output -->
<Reference Include="$(SolutionDir)MarkdownMonster\bin\$(Configuration)\$(TargetFramework)\MarkdownMonster.exe">
<Private>false</Private>
</Reference>
</ItemGroup>
compile in this context means they are available for compilation, but aren't copied to the output folder.
There are two solutions:
1:
<ItemGroup>
<PackageReference Include="PhantomJS" Version="1.0.8" GeneratePathProperty="true" />
</ItemGroup>
<Target Name="CopyPdfExe" AfterTargets="Build">
<Copy SourceFiles="(PkgPhantomJS)\tools\phantomjs\phantomjs.exe" DestinationFolder="$(OutDir)" />
</Target>
2:
<ItemGroup>
<PackageReference Include="PhantomJS" Version="1.0.8" GeneratePathProperty="true" />
</ItemGroup>
<ItemGroup>
<None Include="$(PkgPhantomJS)\tools\phantomjs\phantomjs.exe" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
prefer the #2 since if this project is referenced by another one, the .exe can also be copied to the output folder
The <PackageReference> syntax in NuGet uses transitive dependencies, just like the project.json syntax. As such, the same rules apply. See this NuGet v3 which talks about what does and doesn't work between packages.config and the newer syntax. Specifically
You cannot rely on install.ps1 or uninstall.ps1 to function. These files will execute when using packages.config, but will be ignored in v3. So your package needs to be usable without them running. Init.ps1 will still run on NuGet 3.
To get files to copy to the output directory, the PhantomJS NuGet package needs to be changed to use contentFiles.
The tag names are misleading. Try
<PackageReference Include="PhantomJS" Version="2.1.1">
<IncludeAssets>none</IncludeAssets>
</PackageReference>
or
<PackageReference Include="PhantomJS" Version="2.1.1">
<ExcludeAssets>all</ExcludeAssets>
</PackageReference>
instead in order to get the referenced assemblies and other files copied to the build output. See
https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files
Try dotnet publish
dotnet publish [<PROJECT>] [-c|--configuration] [-f|--framework] [--force] [--manifest] [--no-dependencies] [--no-restore] [-o|--output] [-r|--runtime] [--self-contained] [-v|--verbosity] [--version-suffix]
dotnet publish [-h|--help]
See https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish?tabs=netcore2x
I know this is an old question, but what worked for me was to set IncludeAssets to "runtime"
Actually what is claimed to not work in the original question is what worked for me in .NET6:
<PackageReference Include="PhantomJS" Version="2.1.1">
<IncludeAssets>all</IncludeAssets>
</PackageReference>