Rumah > pembangunan bahagian belakang > Tutorial C#.Net > 关于脚本PowerShell的设计实例

关于脚本PowerShell的设计实例

零下一度
Lepaskan: 2017-06-23 16:11:36
asal
2402 orang telah melayarinya

这几天对PS情有独忠,被它的强大功能所希引,它可以快速部署,快速发布,将一些连带的动作一次的完成,挺方便,类似于早期的bat文件,也像linux平台的bash脚本,但功能上,比前两者都要强很多,下面我们看一下将某个解决方案下的所有项目一次publish的过程,我们使用ps脚本来实现的。

# 作者:仓储大叔
# 功能:发布项目到指定的地方
Param([string] $rootPath)
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path

Write-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
}
Salin selepas log masuk

注意:如果你只是把跨平台项目发到obj\publish文件夹的话,那wwwroot这些文件夹不会生成,而如果发到其它磁盘,将会生成这些静态的文件,这点要注意!

跨平台项目,需要在project.json里把运行时都加上,否则你的项目保能在当前平台运行

  "runtimes": {"win7-x64": {},"linux-x64": {},"osx-x64": {}
  },
Salin selepas log masuk

感谢各位对.net core的支持!

Atas ialah kandungan terperinci 关于脚本PowerShell的设计实例. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan