這幾天對PS情有獨忠,被它的強大功能所希引,它可以快速部署,快速發布,將一些連帶的動作一次的完成,挺方便,類似於早期的bat檔案,也像linux平台的bash指令碼,但功能上,比前兩者都要強很多,下面我們看一下將某個解決方案下的所有項目一次publish的過程,我們使用ps指令碼來實現的。
# 作者:倉儲大叔# 功能:發布項目到指定的地方Param([string] $rootPath)$scriptPath = Split-Path $script:MyInvocation.MyCommand.PathWrite-Host "Current script directory is $scriptPath" -ForegroundColor Yellowif ([string]::IsNullOrEmpty($rootPath)) { $rootPath = "$scriptPath\.."}Write-Host "Root path used is $rootPath" -ForegroundColor Yellow$projectPaths = @{Path="$rootPath\src\LindCore.Manager";Prj="LindCore.Manager.csproj";Name="web"}, @{Path="$rootPath\src\LindCore.Test";Prj="LindCore.Test.csproj";Name="console"} $projectPaths | foreach { $projectPath = $_.Path $projectFile = $_.Prj $name=$_.Name # $outPath = $_.Path + "\obj\publish"$outPath = "d:\publish\"+$name$projectPathAndFile = "$projectPath\$projectFile"Write-Host "Deleting old publish files in $outPath" -ForegroundColor Yellow remove-item -path $outPath -Force -Recurse -ErrorAction SilentlyContinue Write-Host "Publishing $projectPath to $outPath" -ForegroundColor Yellow dotnet restore $projectPathAndFile dotnet build $projectPath dotnet publish $projectPath -o $outPath}
注意:如果你只是把跨平台項目發到obj\publish檔案夾的話,那wwwroot這些檔案夾不會產生,而如果發到其它磁碟,將會產生這些靜態檔案,這點要注意!
跨平台項目,需要在project.json裡把運行時都加上,否則你的項目保能在當前平台運行
"runtimes": {"win7-x64": {},"linux-x64": {},"osx-x64": {} },
感謝各位對.net core的支援!