DotNetCore cross-platform ~ Design of release script PowerShell,
These days, I have a strong liking for PS, and I hope it will be inspired by its powerful functions. It can be quickly deployed and released, and some associated actions can be completed at a time, which is very convenient, similar to the early bat files and bash scripts on the linux platform, the functions are much stronger than those of the previous two, next, let's take a look at the publish process for all projects in a solution, which we implemented using the ps script.
# Author: warehouse uncle # function: release a project to a specified location. 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 \ lincore. manager "; Prj =" lincore. manager. csproj "; Name =" web "}, @ {Path =" $ rootPath \ src \ lincore. test "; Prj =" lincore. 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"-export Yellow dotnet restore $ projectPathAndFile dotnet build $ projectPath dotnet publish $ projectPath-o $ outPath}
Note: If you only send cross-platform projects to the obj \ publish folder, The wwwroot folder will not be generated, and the static files will be generated if it is sent to other disks!
For cross-platform projects, you need to add the runtime in project. json. Otherwise, your project can be run on the current platform.
"runtimes": { "win7-x64": {}, "linux-x64": {}, "osx-x64": {} },
Thank you for your support for. net core!