Last active
April 24, 2020 07:29
-
-
Save NickDarvey/0faa279a6ac52e356e574db1727ef8f7 to your computer and use it in GitHub Desktop.
MSBuild targets for publishing all Azure Function projects in a repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger: | |
branches: | |
include: | |
- master | |
pool: | |
vmImage: 'windows-latest' | |
variables: | |
solution: '**/*.sln' | |
buildPlatform: 'Any CPU' | |
buildConfiguration: 'Release' | |
steps: | |
- task: UseDotNet@2 | |
displayName: 'Get .NET Core SDK' | |
inputs: | |
packageType: sdk | |
version: 2.2.207 | |
continueOnError: true | |
- task: NuGetToolInstaller@0 | |
displayName: 'Get NuGet' | |
inputs: | |
versionSpec: 4.9.1 | |
- task: NuGetCommand@2 | |
displayName: 'Restore' | |
inputs: | |
restoreSolution: '$(solution)' | |
- task: VSBuild@1 | |
displayName: 'Build' | |
inputs: | |
solution: '$(solution)' | |
msbuildArgs: '-m /t:PublishArtifacts /p:ArtifactsDir=$(Build.ArtifactStagingDirectory)' | |
platform: '$(buildPlatform)' | |
configuration: '$(buildConfiguration)' | |
- task: PublishBuildArtifacts@1 | |
displayName: 'Publish' | |
inputs: | |
PathtoPublish: '$(Build.ArtifactStagingDirectory)' | |
ArtifactName: 'drop' | |
publishLocation: 'Container' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" "d:\a\1\s\MySolution.sln" /nologo /nr:false -m /t:PublishArtifacts /p:ArtifactsDir=d:\a\1\a /p:platform="Any CPU" /p:configuration="Release" /p:VisualStudioVersion="16.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project> | |
<PropertyGroup> | |
<StagingDir Condition="'$(StagingDir)' != ''">$([MSBuild]::NormalizeDirectory('$(StagingDir)'))</StagingDir> | |
<StagingDir Condition="'$(StagingDir)' == ''">$([MSBuild]::NormalizeDirectory($(SolutionDir), 'staging'))</StagingDir> | |
<ArtifactsDir Condition="'$(ArtifactsDir)' != ''">$([MSBuild]::NormalizeDirectory($(ArtifactsDir)))</ArtifactsDir> | |
<ArtifactsDir Condition="'$(ArtifactsDir)' == ''">$([MSBuild]::NormalizeDirectory($(SolutionDir), 'artifacts'))</ArtifactsDir> | |
</PropertyGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project> | |
<Import Project="builds\PublishArtifacts.Empty.targets" /> <!-- A do-nothing target --> | |
<Import Project="builds\PublishArtifacts.AzureFunctions.targets" Condition="'$(AzureFunctionsVersion)' != ''"/> <!-- Filtered to Azure Functions projects --> | |
<Target Name="PreparePublishArtifacts" BeforeTargets="PublishArtifacts"> | |
<MakeDir Directories="$(StagingDir);$(ArtifactsDir)" /> | |
</Target> | |
<Target Name="CleanArtifacts" AfterTargets="AfterClean"> | |
<RemoveDir Directories="$(StagingDir);$(ArtifactsDir)" /> | |
</Target> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project> | |
<Target Name="PublishArtifacts"> | |
<PropertyGroup> | |
<_ThisProjectStagingDir>$(StagingDir)$(MSBuildProjectName)</_ThisProjectStagingDir> | |
<_ThisProjectArtifactDir>$([System.IO.Path]::Combine($(ArtifactsDir),'$(MSBuildProjectName)'))</_ThisProjectArtifactDir> | |
</PropertyGroup> | |
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Publish" Properties="PublishDir=$(_ThisProjectStagingDir)" /> | |
<MakeDir Directories="$(_ThisProjectArtifactDir)" /> | |
<ZipDirectory SourceDirectory="$(_ThisProjectStagingDir)" DestinationFile="$(_ThisProjectArtifactDir)\$(MSBuildProjectName).zip" Overwrite="true" /> | |
</Target> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project> | |
<Target Name="PublishArtifacts"> | |
<Message Importance="normal" Text="$(MSBuildProjectFile) has nothing to publish" /> | |
</Target> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Directory.Build.props
andDirectory.Build.targets
go into the root of the repo so they get picked up automatically. Create a directory calledbuild
and addPublishArtifacts.Azure.Functions.targets
or editDirectory.Build.targets
to point to the location of your preference.You can test this locally by running the command in
_publish.bat
or update yourazure-pipelines.yaml
to send the correctmsbuildArgs
in theVSBuild@1
.