文章出處

通過使用ps加上msbuild可以方便的編譯你的.net應用程序,并且可以把它發布到你的磁盤上,部署非常方例!

我們在c盤添加一個hello網站,解決方案名是hello.sln,它的網站是hello.csproj,現在使用這個腳本來生成這個網站和發布這個網站!

$ErrorActionPreference = 'Stop'
# Environment helpers ------------------------------------
Function Get-MsBuildPath() {
    $msBuildRegPath = "HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0"
    $msBuildPathRegItem = Get-ItemProperty $msBuildRegPath -Name "MSBuildToolsPath"
    $msBuildPath = $msBuildPathRegItem.MsBuildToolsPath + "msbuild.exe"
    return $msBuildPath
}


# Environment variables ----------------------------------
$global_buildDirPath = Get-Location
$global_msBuildPath = Get-MsBuildPath
$global_solutionPath = "$global_buildDirPath"
$global_solutionFilePath = "$global_solutionPath\hello.sln"
$global_nugetPath = "$global_buildDirPath\tools\nuget.exe"

 

# Install nuget packages ---------------------------------
Function Install-SolutionPackages() {
    iex "$global_nugetPath restore $global_solutionFilePath"
}
# compile
Function Compile-Publish-Project() {
    iex -Command "& '$global_msBuildPath' '$project_path' /p:Configuration=Release /p:WebProjectOutputDir=C:\publish\hello /p:OutputPath=C:\publish\hello\bin"
}
Install-SolutionPackages
Compile-Publish-Project

最后生成的網站結果為

這個功能對于自動化部署非常有必要,大叔會對這塊內容做進一步的研究和優化!

謝謝!


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()