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.
Related
I'm having trouble ignoring a specific project in my DevOps Pipeline. I have a WPF project in the same solution as my .Net MAUI project and I have a Pipeline for the WPF Solution that works but the .Net MAUI one fails on Nuget Restore because it's Using MAUI and a macOS-12 Image.
- task: DotNetCoreCLI#2
displayName: 'Nuget Restore'
inputs:
command: 'restore'
projects: '**/*.csproj
!**/Portal.Desktop.csproj' # This is supposed to ignore the WPF App
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
I get a pattern matching error though so apparently that's not right
The Error
Nuget Restore
View raw log
Starting: Nuget Restore
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.210.0
Author : Microsoft Corporation
Help : docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
##[error]No files matched the search pattern.
Finishing: Nuget Restore
I can reproduce the match error via using the below YAML:
trigger:
- none
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
displayName: 'Nuget Restore'
inputs:
command: 'restore'
projects: '
**/*.csproj
!**/TestResultsTests.csproj'
feedsToUse: 'select'
vstsFeed: '1f64a82f-77ad-4770-a098-772faae01ed1'
The error disappear after change my YAML to this:
trigger:
- none
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
displayName: 'Nuget Restore'
inputs:
command: 'restore'
projects: | #Here is where I change.
**/*.csproj
!**/TestResultsTests.csproj
feedsToUse: 'select'
vstsFeed: '1f64a82f-77ad-4770-a098-772faae01ed1'
So the issue should comes from your YAML definition.
This is my repository structure:
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
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)'
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.
I have a project that pulls from both public and private NuGet repositories. This works. But what doesn't seem to work is that the build on CI fails because of Microsoft.Bcl.Build, which should have gotten downloaded from the Nuget Restore Step
trigger:
- master
pool:
vmImage: 'windows-2019'
demands:
- msbuild
- visualstudio
- VSTest
- DotNetFramework
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
feedsToUse: config
nugetConfigPath: .nuget/NuGet.Config
- task: VSBuild#1
displayName: 'Run Build on solution.'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)" /p:BclBuildImported=Ignore'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
logFileVerbosity: 'diagnostic'
In the sample above, I have tried both using and removing /p:BclBuildImported=Ignore'.
The library I am using has BCL ref in it, so I cannot remove that dependancy. And this code falls apart when I switch it to core.
Everything does work when I build it in Visual Studio 2019 Ent, and Pro, just refuses to build on MS DevOps, on the Hosted 2017 platform.
Tried fixes, and comment/discussion follow-up since initial post:
Multiple pools have been tried, all failing.
This does build in VS 2017 & 2019 on pro and enterprise on various desktops.
The error is This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets. even though all packages are being installed, and the Nuget download shows no errors or skips.
The following fixes have not worked:
How to bypass Microsoft.Bcl.Build warning
What does the Microsoft.Bcl.Build NuGet package do?
Have you tried MS DevOps, on the Hosted 2019 platform, instead of using a 2017 Host?
Hosted Windows 2019 with VS2019
I ended up removing all BCL dependencies and built a lot of workarounds. This was no minor change. Unfortunately, as this is 2 years ago, I don't have the details of what I did back then.