Azure Devops dotnet build don't respect configuration - c#

In the csproj file of a project I have conditionals for TreatWarningsAsErrors.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
On my computer running
dotnet build solution.sln --Configuration Debug
vs
dotnet build solution.sln --Configuration Release
produces the different results with success and failure as expected.
On our on-prem azure devops server however, even though the log clearly states "--Configuration Release" they show the problems as Warnings. Not failures as expected.
What can be wrong here?
The build log excerpts:
Starting: dotnet build
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.181.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
F:\A\BUILDEDUI12C-B01\_work\_tool\dotnet\dotnet.exe build F:\A\BUILDEDUI12C-B01\_work\754\s\Modules\ScheduleMaker\Backend\ScheduleMaker.sln "-dl:CentralLogger,\"F:\A\BUILDEDUI12C-B01\_work\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.181.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"F:\A\BUILDEDUI12C-B01\_work\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.181.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"" --configuration Release -p:CustomBeforeMicrosoftCommonTargets=F:\A\BUILDEDUI12C-B01\_work\754\s\WE.CI.Tools.Build\Utilities\Education.SonarQube.ImportBefore.targets -p:SQProjectKey=WE.Education.ScheduleMaker
Microsoft (R) Build Engine version 17.1.1+a02f73656 for .NET
[warning]Modules\ScheduleMaker\Backend\Service\WE.Education.ScheduleMaker.Business\Services\ActivityService.cs(61,13): Warning S125: Remove this commented out code.
Edit:
From the diagnostics log i can see that the condition works, it says it changes the variable to True.
2022-04-14T07:06:33.6901214Z Property reassignment: $(TreatWarningsAsErrors)="True" (previous value: "false") at F:\A\BUILDEDUI12A-B01\_work\650\s\Modules\ScheduleMaker\Backend\Service\WE.Education.ScheduleMaker.Business\WE.Education.ScheduleMaker.Business.csproj (19,5)
But It dosen't act as it's true.

The solution, to get it listed as errors in Azure Devops was to add a property so it looked like this:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>False</MSBuildTreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
</PropertyGroup>
Then the setting was property forwarded in Azure Devops to.

Related

wix installer exce command private nuget feed authentication failed

I have an WIX installer 3.11.2 and I want to build an self contained asp.net core application. My project should not have directly the properties set for self contained and runtime identifier. I need to define them by using a condition like:
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'win-x64'">
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
I added to the wix installer a publish with the force. This needed because wix builds the artifacts via the ProjectReference but there the msbuild do not set the parameters correct.
<Target Name="BeforeBuild">
...
<Exec Command="dotnet publish -c $(Configuration) --force -r win-x64 --self-contained -f netcoreapp3.1" WorkingDirectory="%(ProjectReference.RootDir)%(ProjectReference.Directory)" />
...
</Target>
Now my build failed on Azure DevOps with the error: C:\hostedtoolcache\windows\dotnet\sdk\3.1.415\NuGet.targets(128,5): error : Response status code does not indicate success: 401 (Unauthorized).
I can build successful the installer on my local machine.
If the self contained property is set directly in the project and I remove the --force parameter from the dotnet publish command everything works fine.
Has any one an idea or fix how I can fix this behavior? Is there any way to pass the credentials to the wix installer through msbuild?

Azure Pipeline: dotnet publish fails - assets.json doesn't have a target for '.NETCoreApp,Version=v3.1/win-x64'

I have a .NetCore 3.1 commandline app. When buidling locally and publishing, it works completely fine using below commandline
dotnet publish -c dev -r win-x64 --self-contained true
In the Azure pipeline - I had to do the dotnet restore before doing a publish using the above command. Whilst publishing I had to add extra param --no-restore, as per Microsoft's recommendation here as I have private nuget feeds.
dotnet publish -c dev -r win-x64 --self-contained true --no-restore
Most dotnet commands, including build, publish, and test include an
implicit restore step. This will fail against authenticated feeds,
even if you ran a successful dotnet restore in an earlier step,
because the earlier step will have cleaned up the credentials it used.
To fix this issue, add the --no-restore flag to the Arguments textbox.
Now, the publish part of the pipeline has started failing with the error -
C:\Program Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1047: Assets file 'MyProject\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.1/win-x64'. Ensure that restore has run and that you have included 'netcoreapp3.1' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers.
Am not using a publish xml, but specifying all the arguments as shown above in the command line. I've checked the csproj has the target framework specified
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;dev;test;pre;prod</Configurations>
</PropertyGroup>
Need any pointers as to what might be going wrong here?
Thanks
Please add RuntimeIdentifier as mentioned in the error message:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;dev;test;pre;prod</Configurations>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
Please also check PlatformTarget.
<PlatformTarget>AnyCPU</PlatformTarget>
I guess the local machine has a different OS than the build agent.

Dotnet publishing via cmd not possible

I'm successfully publishing a .NET Core App via Visual Studio but am unable to do the same via command-line (or using the Developer Command Prompt for VS 2019).
I'm using the Publish profile generated by VS2019 and doing:
dotnet publish -p:PublishProfile=Properties\PublishProfiles\MyProfile.pubxml
where MyProfile is:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PublishDir>..\Build\Release\publish\</PublishDir>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
</Project>
And the error that I always get is:
MyCustom.dll. Could not load type
'Microsoft.Build.Utilities.AppDomainIsolatedTask' from assembly
'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'. Confirm that the
declaration is correct, that the assembly and all its dependencies are
available, and that the task contains a public class that implements
Microsoft.Build.Framework.ITask.
What am I missing?
I found a workaround, rather than a fix.
If we use msbuildto publish, I'm able to have the same result as dotnet publish and it runs successfully in the command-line:
msbuild /restore /t:Publish /p:RuntimeIdentifier=win-x64 /p:configuration=Release

VSTS - Uno with Xamarin iOS Build error for C# 7.1 feature while LangVersion is properly set

When building on vsts (windows hosted machine) I have the following error:
Operator '==' cannot be applied to operand 'default'
However, in my project I have:
<PropertyGroup>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
Moreover, on my machine it does build (in Debug AND Release modes).
UPDATE
The error first appeared while I had the following:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>7.1</LangVersion>
</PropertyGroup>
Note that this is a library and that I do multi-targeting (netstandard2.0;xamarinios10) but I don't see why it should matter.
UPDATE2
I tried
<PropertyGroup>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
Looking in the logs I see:
/reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Xml.Xsl.Primitives.dll /debug- /debug:portable /filealign:512 /nologo /optimize+ /out:obj/Release/xamarinios10/MyApp.ViewModels.dll /target:library /warnaserror- /utf8output /deterministic+ /langversion:latest /analyzer:/Users/vsts/.nuget/packages/uno.ui/1.31.0-dev.8/analyzers/Uno.Analyzers.dll MyViewModelA.cs MyViewModelB.cs... Parameter.cs ReactiveGroup.cs "/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/Xamarin.iOS,Version=v1.0.AssemblyAttributes.cs" obj/Release/xamarinios10/MyApp.ViewModels.AssemblyInfo.cs /warnaserror+:NU1605
2018-06-27T20:11:28.5184750Z MyViewModelA.cs(105,89): error CS8310: Operator '==' cannot be applied to operand 'default' [/Users/vsts/agent/2.134.2/work/1/s/MyApp.ViewModels/MyApp.ViewModels.csproj]
So I think it may not be a build error but some kind of Uno Analyser error.
Side note: it is strange that the log mentions uno.ui/1.31.0-dev.8 as I had upgraded the package (see below). As if there were some caching involved I don't know how.
<PackageReference Include="Uno.UI" Version="1.31.0-dev.79" />
UPDATE3
I can't copy the full log here but here the csc command for the project that fails to build:
/Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/4.5/csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705 /langversion:latest /nostdlib+ /errorreport:prompt /warn:4 /define:__IOS__;__MOBILE__;__UNIFIED__;TRACE;RELEASE;XAMARINIOS1_0
UPDATE4
Thanks to #JeromeLaban, who provided me with that link about Mono 5.8.0, as it shows that version of mono is compatible with C# 7.0 only.
However, the specs of the MacOs queue say that there is Mono 5.10 installed and that version is up to C# 7.2.
So the next question (and I wrote a dedicated question) is how to specify the mono version to build with.
The xamarinios vsts task that I run on the hosted vsts MacOs queue runs mono 5.8.0 (even though mono 5.10.0 is installed on that queue as per specs). And version 5.8.0 is compatible up to C# 7.0 so it cannot run C# 7.1 code.

Visual Studio 2017 RC Core Console Project does not compile

When I create a new enoty core console project it doesn't compile
I can see that the nuget packages are not restored.
when i run dotnet restore i get the error
microsoft.net.sdk\1.0.0-alpha-20161104-2\build\Microsoft.NET.RuntimeIdentifierInference.targets(45,5):
error : RuntimeIdentifier must be set for .NETFramework executables.
Consider RuntimeIdentifier=win7-x86 or RuntimeIdentifier=win7-x64.
what am i missing?
As suggested by #annemartijn, but then without the s
<RuntimeIdentifier>win7-x64</RuntimeI‌​dentifier>
See issue on github: https://github.com/dotnet/cli/issues/4619
Insert the runtime identifier segment in your .csproj file:
<Project...
<Import...
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
...
<RuntimeIdentifier>win7-x64</RuntimeI‌​dentifier>
</PropertyGroup>
...

Categories

Resources