Question

Oh great powershell gods, please show this heathen the light!

I have been tasked with creating a 1 click publish-our-solution-to-the-cloud powershell script. I have, however, never used PS in my life. I have therefore been doing quite a bit of Googling and found a good bit of information however where I want to start I'm having a little difficulty finding something I can wrap my head around.

I keep running across pre/post build scripts, VS management console, nuget package management or any other number of seemingly unrelated info. These are not what I'm looking for.

Either by example here or linking to a good tutorial to get me started. My first baby step is to get VS to package the solution for release. Do the below action via PS.

Image for clarity, just in case...

I thought this would be the easiest to find info on... I have seen some info on MSBuild which I'm looking into now as I hopefully get an answer here.

EDIT: My working PS Script

$msbuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" # Reference to the MSBuild.exe for .NET 4.0
$path = "C:\myProj\"                                  # Path to the project you want to publish to Azure 

# Clean the solution
& $msbuild ($path + "Source\pathToYour\AzureMyProj.ccproj") /target:clean /p:Configuration=Release

# Package the solution
& $msbuild ($path + "Source\pathToYour\AzureMyProj.ccproj") /target:publish /p:Configuration=Release
Was it helpful?

Solution

you can use MSBuild for this purpose. This is how I do it for my projects:

So from powershell, you could call it like this:

.\MSBuild MyProject.proj /target:package /p:Configuration=Release

EDIT 25/06: Worked for James with the /target:publish

Note: You may need to specify the location of MSBuild as a variable, this can be found under C:\Windows\Microsoft.Net\Framework\versionNumber\

In that case it'd become:

$msbuild = "C:\Windows\Microsoft.NET\Framework64\v2.0.50727\msbuild.exe"
& $msbuild MyProject.proj /target:package /p:Configuration=Release

Notice the & instead of the .\ this tells powershell to execute the variable (which in this case is an exe).

Also, further to your problem of not really knowing how to do it. I use a build language called PSake which is a PowerShell based build language which may be of use to you. It's pretty useful: https://github.com/psake/psake

Hope this helps.

OTHER TIPS

For Web Deploy 3 I had a few problems separating the arguments correctly. From a template MVC4 application the following worked for me.

$msbuild = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"
$buildCommand = "& $msbuild MvcApplication.csproj '/target:package' /P:Configuration=Release"

Write-Host
Write-Host "[$scriptName] $buildCommand"
Invoke-Expression $buildCommand
$exitcode = $LASTEXITCODE
if ( $exitcode -gt 0 ) { 
    Write-Host
    Write-Host "[$scriptName] Build using Web Deploy failed with exit code = $exitcode" -ForegroundColor Red
    throw "Build using Web Deploy failed with exit code = $exitcode" 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top