Design examples about scripting PowerShell

零下一度
Release: 2017-06-23 16:11:36
Original
2287 people have browsed it

这几天对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
}
Copy after login

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

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

  "runtimes": {"win7-x64": {},"linux-x64": {},"osx-x64": {}
  },
Copy after login

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

The above is the detailed content of Design examples about scripting PowerShell. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!