wix installer exce command private nuget feed authentication failed - c#

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?

Related

Azure Devops dotnet build don't respect configuration

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.

Unable to publish Azure function app v3 C# with .net 5

I am unable to publish my .net function app. I am using the below configuration and settings:
.net 5 SDK Version: 5.0.300
Microsoft.Azure.Functions.Worker 1.2.0
Microsoft.Azure.Functions.Worker.Core 1.1.0
Getting below error:
Metadata generation failed. Exit code: '-532462766' Error: 'Error generating extension metadata: System.IO.DirectoryNotFoundException: The path PATH\bin\Release\net5.0\publish\bin does not exist. Unable to generate Azure Functions extensions metadata file.
The problem lies with the .targets file of Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator, it sets the _FunctionsExtensionsDir to the publish target directory + 'bin'
So if you publish to project-path\bin\release\net5.0\publish, it's looking for published output in project-path\bin\release\net5.0\publish\bin - you can prove this by doing a replace all in the .targets file replacing ')bin' with ')' and watching it run as expected.
A quick and dirty solution is to build with the -o flag set to where the metadata generator will expect the output to be, e.g.
dotnet build yourproject.csproj --framework net5.0 -c release -o c:/temp/output/bin -v d
dotnet publish yourproject.csproj --framework net5.0 -c release -o c:/temp/output -v d
I'm currently looking into a less hacky way of achieving this, and will post if/when I figure it out.
This looks like a bug in Visual Studio 2019.
Suggestion:
Record your current version, you can raise a support ticket to confirm with the official.
Upgrade your vs2019 to the latest version and try to publish again.

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.

How can bindings for azure function be added at compile time with MSBuild?

I have an azure function C# project in visual studio which has a few service bus topic triggers. I have a powershell script which can be run to copy the function.json files generated in bin and convert them to queue bindings. The only problem is that azure functions introduce a private target in msbuild after the Build target called _GenerateFunctionsPostBuild . So I am trying to look for a way to run a powershell script after this step so my changes dont get erased by the unique builds for azure functions.
So I am trying to look for a way to run a powershell script after this step so my changes dont get erased by the unique builds for azure functions.
To accomplish this, you can add a custom to execute the powershell script after the target _GenerateFunctionsPostBuild, like <Target Name="InvokePowerShell" AfterTargets="_GenerateFunctionsPostBuild">.
Details steps:
Right your project, select Edit YourProjectName.csproj.
At the very end of the project, just before the end-tag </Project>
, place below scripts:
<Target Name="InvokePowerShell" AfterTargets="_GenerateFunctionsPostBuild">
<PropertyGroup>
<PowerShellExe Condition=" '$(PowerShellExe)'=='' ">
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
</PowerShellExe>
<ScriptLocation Condition=" '$(ScriptLocation)'=='' ">
C:\Path With Spaces\LogDeploy.ps1
</ScriptLocation>
<LogFileLocation Condition=" '$(LogFileLocation)'=='' ">
C:\Path With Spaces\ContactManagerDeployLog.txt
</LogFileLocation>
</PropertyGroup>
<Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted
-command "& {
&&apos;$(ScriptLocation)&apos;
&apos;$(LogFileLocation)&apos;
&apos;$(MSDeployComputerName)&apos;} "" />
</Target>
Then the powershell script would be executed after the target _GenerateFunctionsPostBuild.
For Target Build Order and Running Windows PowerShell Scripts from MSBuild Project Files for some more details.
Hope this helps.

Detect the BuildType in Dotnet Core 2.0

I am looking to have a condition in my .csproj whereby I detect the buildType. Is there a property that gives me this information?
For example, I am wanting to detect when a build is triggered from dotnet build or dotnet publish
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition="'$(BuildType)' != 'publish'">
...
</Target>

Categories

Resources