Last active
September 3, 2021 16:24
-
-
Save wllmsash/62e4951fc394afd4f36fda32d30c1864 to your computer and use it in GitHub Desktop.
Publish a dotnet solution to an output directory
This file contains hidden or 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
#Requires -Version 7 | |
$configuration = "Release" | |
$output_directory_name = "publish" | |
$target_projects = "Project1","Project2","Project3" | |
$dotnet_version_directory = "netcoreapp3.1" | |
# Publish a clean build for every project in the solution | |
dotnet clean --configuration "$configuration" | |
If ($LastExitCode -ne 0) | |
{ | |
Write-Host -ForegroundColor Red "Error: dotnet clean failed" | |
exit $LastExitCode | |
} | |
dotnet publish --configuration "$configuration" | |
If ($LastExitCode -ne 0) | |
{ | |
Write-Host -ForegroundColor Red "Error: dotnet publish failed" | |
exit $LastExitCode | |
} | |
# Create a clean output directory | |
Remove-Item (Join-Path "." "$output_directory_name") -Recurse -ErrorAction Ignore | |
If (!(Test-Path (Join-Path "." "$output_directory_name"))) | |
{ | |
New-Item -ItemType Directory -Force -Path (Join-Path "." "$output_directory_name") | |
} | |
# Copy target published assets to output directory | |
Foreach ($project in $target_projects) | |
{ | |
echo "Copying assets for $project..." | |
Copy-Item -Path (Join-Path "." "$project" "bin" "$configuration" "$dotnet_version_directory" "publish") -Destination (Join-Path "." "$output_directory_name" "$configuration" "$project") -Recurse | |
} | |
echo "Finished!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment