create a clickonce package on local machine from Azure pipeline? - yaml

I am tasks with adding steps to a pipeline that will create and deploy a clickonce application from an application. Here is what I have so far for my yml file:
trigger:
- ReleaseCandidate
pool:
name: 'PoolTest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: 'CTVdbNG.Master/NuGet.config'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/target:publish /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 only build and test...but how do I create a clickonce package?

create a clickonce package on local machine from Azure pipeline?
There is no directly way or argument to generate the package for the clickonce project.
To generate the package, you could edit the project file for your client project and add the following at the bottom (right above the tag):
<PropertyGroup>
<!--Unless specified otherwise, the tools will go to HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1 to get the installpath for msdeploy.exe.-->
<MSDeployPath Condition="'$(MSDeployPath)'==''">$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\3#InstallPath)</MSDeployPath>
<MSDeployPath Condition="'$(MSDeployPath)'==''">$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\2#InstallPath)</MSDeployPath>
<MSDeployPath Condition="'$(MSDeployPath)'==''">$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1#InstallPath)</MSDeployPath>
<MSDeployExe Condition=" '$(MSDeployExe)'=='' ">$(MSDeployPath)msdeploy.exe</MSDeployExe>
</PropertyGroup>
<Target Name="CreateWebDeployPackage" AfterTargets="Publish" DependsOnTargets="Publish">
<!--
%msdeploy%
-verb:sync
-source:contentPath="C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\app.publish"
-dest:package="C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\co-pkg.zip"
-->
<PropertyGroup>
<Cmd>"$(MSDeployExe)" -verb:sync -source:contentPath="$(MSBuildProjectDirectory)\$(PublishDir)" -dest:package="$(OutDir)cotest.zip"</Cmd>
</PropertyGroup>
<Message Text="Creating web deploy package with command: $(Cmd)" />
<Exec Command="$(Cmd)" />
</Target>
It will generate the cotest.zip under the path bin\Debug\cotest.zip.
Source reference: Create a clickonce webdeploy package

Related

Building azure pipeline with .NET 5.0, warnings?

So am trying to build a pipeline in Azure for a WebApi app developed in .Net 5.0, however when I run the standard yaml pipeline (asp.net core) I get the following warnings:
Tvattstugan\Tvattstugan.csproj(0,0): Warning NU1701: Package 'Microsoft.AspNet.Cors 5.2.7' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project.
I checked out a previous post on SO and tried experimenting with answers from that thread to comment out the nuget tasks and insert UseDotNet task but that only gave me more warnings so commented out those suggestions.
If anybody could explain the procedure and how to get around this I would be very appreciative. Here is my pipeline.yml:
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: UseDotNet#2
# inputs:
# packageType: 'sdk'
# version: '5.0.x'
# - task: DotNetCoreCLI#2
# displayName: 'dotnet build'
# inputs:
# command: 'build'
- 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)'

Automatic version numbering for iOS Xamarin project in Azure Pipelines

For my project (Mobile iOS application, based on Xamarin) I have set up Azure Pipelines build process.
I would like to automatically increase and set the ipa-file version for every build.
Upon searching the Internet I have found an article that advises to add the following code to the ios project .csproj file:
<Target Name="BeforeBuild" Condition=" $(SetVersion) == true ">
<GetAssemblyIdentity AssemblyFiles="$(AssemblyPath)">
<Output TaskParameter="Assemblies" ItemName="AssemblyInfo" />
</GetAssemblyIdentity>
<PropertyGroup>
<VersionNumber>$([System.Text.RegularExpressions.Regex]::Match(%(AssemblyInfo.Version), `[^.][^.]*.[^.]*.[^.]*`))</VersionNumber>
</PropertyGroup>
<XmlPoke XmlInputPath="Resources/Info.plist" Query="//dict/key[. = 'CFBundleVersion']/following-sibling::string[1]" Value="$(BuildNumber)" />
<XmlPoke XmlInputPath="Resources/Info.plist" Query="//dict/key[. = 'CFBundleShortVersionString']/following-sibling::string[1]" Value="$(VersionNumber)" />
I set version number manually and as I don't need the assembly version number I have added this simplified code to my iosProject.csproj file:
<Target Name="BeforeBuild" Condition=" $(SetVersion) == true ">
<XmlPoke XmlInputPath="Info.plist" Query="//dict/key[. = 'CFBundleVersion']/following-sibling::string[1]" Value="$(BuildNumber)" />
<XmlPoke XmlInputPath="Info.plist" Query="//dict/key[. = 'CFBundleShortVersionString']/following-sibling::string[1]" Value="$(VersionNumber).$(BuildNumber)" />
</Target>
In my azure-pipelines.yml file I have the following command line with hardcoded values (just for debugging purposes) for msbuild call:
variables:
mobileProjectMSbuildArgumentsForIOS: "/p:SetVersion=true /p:VersionNumber=1.0 /p:BuildNumber=34 /bl:$(Build.ArtifactStagingDirectory)/build_iOS.binlog"
As you can see, SetVersion is true, VersionNumber is 1.0 and BuildNumber is 44.
Tasks to make the build and generate binary log are as follows:
- task: XamariniOS#2
inputs:
solutionFile: '**/*iOS.csproj'
signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
signingProvisioningProfileID: '$(APPLE_PROV_PROFILE_UUID)'
configuration: '$(buildConfiguration)'
msbuildArguments: "$(mobileProjectMSbuildArgumentsForIOS)"
outputDirectory: "$(outputDirectory)"
packageApp: true
args: /p:IpaPackageDir="$(outputDirectory)"
- task: PublishBuildArtifacts#1
displayName: 'Publish binary log'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'Binary log'
publishLocation: 'Container'
condition: succeededOrFailed()
But when the project has been built using pipelines, the build is green, but:
The version of the ipa-file has not set to the expected 1.0.34, it has old value, that was set manually in .plist file in the project.
binary log is not being generated. upon running task to publish the binary log I get the message:
##[warning]Directory '/Users/runner/work/1/a' is empty. Nothing will be added to build artifact 'Binary log'.
My questions:
Why XmlPoke does not work for ios.csproj file, even SetVersion is set to true?
Why binary log is not being generated?
Any ideas are welcome.
Thank you.
I found you had mistakes in XamariniOS#2 task. Fields msbuildArguments And outputDirectory are fields for Xamarin.Android task. They donot exist for Xamarin.iOS task
So you can try moving /p:IpaPackageDir="$(outputDirectory)" And outputDirectory: "$(outputDirectory)" to your mobileProjectMSbuildArgumentsForIOS variable.
variables:
mobileProjectMSbuildArgumentsForIOS: "/p:OutputPath=$(outputDirectory) /p:IpaPackageDir="$(outputDirectory)" /p:SetVersion=true /p:VersionNumber=1.0 /p:BuildNumber=34 /bl:$(Build.ArtifactStagingDirectory)/build_iOS.binlog"
Then assign the msbuildArguments to args fields: args: "$(mobileProjectMSbuildArgumentsForIOS)"
See below changed the XamariniOS#2 task:
- task: XamariniOS#2
inputs:
solutionFile: '**/*iOS.csproj'
signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
signingProvisioningProfileID: '$(APPLE_PROV_PROFILE_UUID)'
configuration: '$(buildConfiguration)'
args: "$(mobileProjectMSbuildArgumentsForIOS)"
packageApp: true

How to Specify .NET Framework Version in YAML Pipeline?

I'm extremely new to YAML--I'm trying to update a plug-in library using the published artifact DLL from build B (see YAML below) however I keep receiving the following error:
How can I specify the .NET Framework in the YAML so that it is not trying to use an old version? I need it to use 4.6.2. I've browsed every Microsoft Doc and found that you can specify it running tests but have had zero luck trying to find how to set it for a build.
Just to clarify, the YAML below successfully runs and I can download the DLL but upon updating the plug-in registration it will result in the error.
'''
trigger: none
pool:
vmImage: 'windows-latest'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: 'A/A.sln'
#Build the solutions
- task: VSBuild#1
displayName: 'Build A Library'
inputs:
solution: 'A/A.sln'
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: 'Any CPU'
configuration: 'Release'
- task: VSBuild#1
displayName: 'Build B Library'
inputs:
solution: 'B/B/B.sln'
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: 'Any CPU'
configuration: 'Release'
- publish: $(System.DefaultWorkingDirectory)/B/B/B/bin/Release/B.dll
artifact: BDll
'''
From the linked doc in the issue, the cause of the issue is that In the .NET Framework version 3.5 and earlier versions, if you loaded an assembly from a remote location, the assembly would run partially trusted with a grant set that depended on the zone in which it was loaded. If you try to run that assembly in the .NET Framework version 4 and later versions, an exception is thrown.
You can add this line in your config file:
<configuration> <runtime> <loadFromRemoteSources enabled="true"/> </runtime> </configuration>
If you want to target .NET Framework 4.6.2, you can add this line in the msbuildArgs of YMAL:
/p:TargetFrameworkVersion="v4.6.2"
If you don't add this line, it will use the default old .NET Framework when build.

Azure Devops Build Fail when using GeneratePathProperty true for PackageReference

We have set up a Project in Visual Studio where we are using NuGet Packages references. For one of the NuGet Packages we are setting the GeneratePathProperty to true, so that we can copy the files from the NuGet package location to the Output bin folder of our Project
He have configured the .csproj file as below:
<PackageReference Include="ilmerge" GeneratePathProperty="true">
<Version>3.0.29</Version>
</PackageReference>
<None Include="$(Pkgilmerge)\tools\net452\ILMerge.exe">
<Link>ILMerge.exe</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="$(Pkgilmerge)\tools\net452\System.Compiler.dll">
<Link>System.Compiler.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
This works perfectly fine locally (using Visual Studio 2019) - project compiles and files are copied to the bin folder, however in our Build Pipeline using the windows-2019 hosted agent (that should also have VS 2019 as per the documentation https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md) this fails during the Build Task:
[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4601,5): Error MSB3030: Could not copy the file 'd:\tools\net452\ILMerge.exe' because it was not found.
[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4601,5): Error MSB3030: Could not copy the file 'd:\tools\net452\System.Compiler.dll' because it was not found.
The Build Definition has following tasks
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
displayName: 'Restore Nugets'
inputs:
restoreSolution: '$(solutions)'
vstsFeed: 'Project-Packages'
- task: VSBuild#1
inputs:
solution: '$(solutions)'
platform: 'Any CPU'
configuration: 'Release'
logProjectEvents: false
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.StagingDirectory)'
artifactName: $(pluginName)
condition: always()
Any ideas what could be the issue or what we need to change in order for the build in Azure DevOps to work?
Later Edit: I added some logging
<Target Name="¨ReMerge" AfterTargets="ILRepacker" >
<Message Text="Remerging Assemblies using ILMerge from $(Pkgilmerge) and setting AssemblyVersion = 2.0.0.0" Importance="High" />
<Exec Command="dir $(Pkgilmerge)"></Exec>
<Exec Command="$(Pkgilmerge)\tools\net452\ILMerge.exe /ver:2.0.0.0 /out:$(TargetDir)$(TargetName)Merged.dll /keyfile:$(ProjectDir)Zurich.Zkp.Key.snk $(TargetDir)$(TargetName)MergedTemp.dll"></Exec>
</Target>
And it seems that in AzureDevops the $(Pkgilmerge) is empty
Thank you
The above error was caused by an old version(4.x) Nuget being used to restore your solution.
You need to specify the Nuget version to the newest for your NuGetToolInstaller task, if unspecified, a version will be chosen automatically.
Check below example to specify NuGetToolInstaller task to use 5.4.x version of Nuget.
- task: NuGetToolInstaller#0
inputs:
versionSpec: 5.4.x

Multiline string in Azure Pipelines

Can I use a multiline YAML string in Azure Pipelines?
Using the ASP.NET Core (.NET Framework) template I tried multilining the msbuildArgs but that didn't work.
- 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)'
MSBUILD : error MSB1008: Only one project can be specified.
Switch: '/p:DeployOnBuild=true
Reviewing the string reference documentation I don't see any about this topic.
I always use the YAML block chomping operator like this
msbuildArgs: >-
/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip"
/p:DeployIisAppPath="Default Web Site"
Works well and makes things crystal clear and neat
You can just put ' in the start and the end of the msbuildArgs:
- task: VSBuild#1
displayName: 'Build solution **\*.sln'
inputs:
vsVersion: latest
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true'
Multiline string in Azure Pipelines
Shayki Abramczyk pointed out the key to the this error.
Just put one ' in the start and the end of the msbuildArgs
without having to configure for each MSBuild argument
As test, following YAML work for me:
- task: VSBuild#1
displayName: 'Build solution YourSolution'
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)'
Note: The variable $(solution) should point to a specific solution .sln or project .csproj file instead of **\*.sln. If you have one more solution in your repo, you may get the error Only one project can be specified.
Update:
but I don’t want super long run-on line as in your answer provided. I
want to split across multiple lines!
If you do not want to super long run-on line as in MSBuild arguments, you could split them directly, but pay attention to indentation, like:
- task: VSBuild#1
displayName: 'Build solution YourSolution'
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)'
As test, it works fine.
Hope this helps.

Resources