Categories
PowerShell

.Net Publish Using PowerShell

Sometimes we want to publish project using PowerShell rather then using Visual Studio Publish feature. I wanted to published all projects of the solutions in one folder. Below PowerShell command will published our projects in __DEPLOY__ folder as an example.

cd src
$paths = Get-ChildItem -include *.csproj -Recurse
foreach($pathobject in $paths)
{
     cd $pathobject.directory.fullName
     dotnet publish -o ..\..\__DEPLOY__\Program
}
cd ..\..

Save this code as PowerShell script with extension of ps1. Run this script from VS, we need to open VS in elevated permission, open “Developer PowerShell” navigate to the script folder and run the script.
You may face an error with error message
“FullyQualifiedErrorId : UnauthorizedAccess”

To resolve this error run this command to by pass security exception

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Run the PowerShell Script again, it should run it without any issue. And all you published files and folder should be in “__DEPLOY__” folder.

Happy Hacking 🙂

One reply on “.Net Publish Using PowerShell”

Leave a Reply

Your email address will not be published. Required fields are marked *