Some additional context: I created a solution using the Angular project template with ASP.NET Core in Visual Studio 2019. The app has several different environments: DEV, STG, and Production. There are corresponding "appsettings.json" files for the .NET project ("appsettings.DEV.json", "appsettings.STG.json", "appsettings.Production.json"), as well as "environment.ts" files in the "ClientApp" folder ("environment.DEV.ts", "environment.STG.ts", "environment.Production.ts"). This app will be deployed to IIS on a Windows Server, and I have created ".pubxml" publish profiles targeting a folder for each of these environments.
The project template generates the following in the .csproj file:
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />
</Target>
The .pubxml files I created set the value of ASPNETCORE_ENVIRONMENT
like this:
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="DEV" />
</environmentVariables>
I have also added build scripts for the Angular client app in the "package.json" file for each environment:
"scripts": {
"build-dev": "ng build -c DEV",
"build-stg": "ng build -c STG",
"build-prod": "ng build -c Production",
}
However, I would like to specify which of those scripts to run, depending on which publish profile was selected. I tried modifying the ".csproj" file with the following, but it does not work. I can't figure out how to get the value of ASPNETCORE_ENVIRONMENT
in the .csproj file:
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build-dev" Condition="'$(ASPNETCORE_ENVIRONMENT)' == 'DEV'" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build-stg" Condition="'$(ASPNETCORE_ENVIRONMENT)' == 'STG'" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build-production" Condition="'$(ASPNETCORE_ENVIRONMENT)' == 'Production'" />
</Target>
What is the correct way to publish the entire app, building both the .NET app and the Angular app in the "ClientApp" folder for different environments?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…