Skip to content

Instantly share code, notes, and snippets.

@steliodibello
Created November 29, 2019 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steliodibello/465e2a7d3ed660664fe9a49294570b53 to your computer and use it in GitHub Desktop.
Save steliodibello/465e2a7d3ed660664fe9a49294570b53 to your computer and use it in GitHub Desktop.
This code snippet to a MsBuild Publish within an Helix style solution
Write-Host $Env:BUILD_SOURCESDIRECTORY
$foundationPath = Join-Path -Path $Env:BUILD_SOURCESDIRECTORY -ChildPath "Website/src/Foundation"
Write-Host "found path $foundationPath"
$featurePath = Join-Path -Path $Env:BUILD_SOURCESDIRECTORY -ChildPath "Website/src/Feature"
Write-Host "found path $featurePath"
$projectPath = Join-Path -Path $Env:BUILD_SOURCESDIRECTORY -ChildPath "Website/src/Project"
Write-Host "found path $projectPath"
$tempOutputfolder = Join-Path -Path $Env:BUILD_SOURCESDIRECTORY -ChildPath "Website/temp"
Write-Host "Temp fold $tempOutputfolder"
$msBuildExe = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe"
Write-Host "Trying to get build file $msBuildExe"
Write-Host "Trying to build into $Env:BUILD_ARTIFACTSTAGINGDIRECTORY "
Write-Host "Trying to get build dir $Env:AGENT_BUILDDIRECTORY"
if ((Test-Path $foundationPath) -eq $True) {
$foundationProjects = Get-ChildItem $foundationPath -Recurse -Include *.csproj
foreach ($projectFile in $foundationProjects) {
if ($projectFile -notlike "*Tests*")
{
Write-Host "Foundation $projectFile "
#$testproj = $projectFile
& "$($msBuildExe)" "$($projectFile)" /m /nr:false /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:Configuration=release /p:PublishUrl=$tempOutputfolder
#& "$($msBuildExe)" "$($projectFile)" /m /nr:false /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:Configuration=debug /p:PublishUrl=$publishTarget -v:q -nologo -clp:NoSummary > null
#if ($LastExitCode -ne 0) {
# Write-Host "Build failed for" $projectFile -foregroundcolor Magenta
# exit
#}
}
}
}
if ((Test-Path $featurePath) -eq $True) {
$featureProjects = Get-ChildItem $featurePath -Recurse -Include *.csproj
foreach ($projectFile in $featureProjects) {
if ($projectFile -notlike "*Tests*")
{
Write-Host "Feature $projectFile "
& "$($msBuildExe)" "$($projectFile)" /m /nr:false /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:Configuration=release /p:PublishUrl=$tempOutputfolder
#& "$($msBuildExe)" "$($projectFile)" /m /nr:false /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:Configuration=debug /p:PublishUrl=$publishTarget -v:q -nologo -clp:NoSummary > null
#if ($LastExitCode -ne 0) {
# Write-Host "Build failed for" $projectFile -foregroundcolor Magenta
# exit
#}
}
}
}
if ((Test-Path $projectPath) -eq $True) {
$projectPathProjects = Get-ChildItem $projectPath -Recurse -Include *.csproj
foreach ($projectFile in $projectPathProjects) {
if ($projectFile -notlike "*Tests*")
{
Write-Host "Project $projectFile "
& "$($msBuildExe)" "$($projectFile)" /m /nr:false /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:Configuration=release /p:PublishUrl=$tempOutputfolder
#& "$($msBuildExe)" "$($projectFile)" /m /nr:false /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:Configuration=debug /p:PublishUrl=$publishTarget -v:q -nologo -clp:NoSummary > null
#if ($LastExitCode -ne 0) {
# Write-Host "Build failed for" $projectFile -foregroundcolor Magenta
# exit
#}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment