dotnet publish /p:EnvironmentName=Staging 不起作用

huangapple go评论58阅读模式
英文:

dotnet publish /p:EnvironmentName=Staging not work

问题

我尝试使用以下命令发布我的ASP.Net 5解决方案:

dotnet publish -c Release -r ubuntu.18.04-x64 --self-contained false /p:DebugType=None /p:DebugSymbols=false /p:EnvironmentName=Staging

这个命令在这里找到。

但是,我仍然在日志中看到EnvironmentNameProduction。我做错了什么?

我还尝试添加以下内容到WebApp的.csproj文件中:

<PropertyGroup Condition=" '$(Configuration)' != '' AND '$(Configuration)' != 'Debug' ">
    <EnvironmentName>'$(Configuration)'</EnvironmentName>
  </PropertyGroup>

但结果仍然一样 - 什么都没有改变。

英文:

I tried to publish my ASP.Net 5 solution via

dotnet publish -c Release -r ubuntu.18.04-x64 --self-contained false /p:DebugType=None /p:DebugSymbols=false /p:EnvironmentName=Staging

that found here.

But I still see in logs that EnvironmentName is Production. What did I do wrong?

I also tried to add

<PropertyGroup Condition=" '$(Configuration)' != '' AND '$(Configuration)' != 'Debug' ">
    <EnvironmentName>'$(Configuration)'</EnvironmentName>
  </PropertyGroup>

into WebApp .csproj, but the result is the same - nothing changes.

答案1

得分: 2

这种方法只在将应用程序部署到IIS时才有效 (文档)。

基于您的发布命令

dotnet publish -c Release -r ubuntu.18.04-x64 --self-contained false
/p:DebugType=None /p:DebugSymbols=false /p:EnvironmentName=Staging

您正在为 ubuntu.18.04-x64 构建它,因此您将不使用IIS。
要在Linux上更改 EnvironmentName,您将需要执行以下之一

  1. 设置环境变量为 ASPNETCORE_ENVIRONMENT=Staging
  2. 在运行应用程序时将环境作为命令行参数发送 : "dotnet .\webapi.dll environment=staging"
英文:

This approach is valid only if you deploy your application on IIS (docs).

Based on your publish command
> dotnet publish -c Release -r ubuntu.18.04-x64 --self-contained false
> /p:DebugType=None /p:DebugSymbols=false /p:EnvironmentName=Staging

You are building it for ubuntu.18.04-x64, therefore you will not be using IIS.
To change the EnvironmentName on Linux you will have to do one of the following:

  1. Setup env variable ASPNETCORE_ENVIRONMENT=Staging.
  2. Send enviroment as cli argument when you run the application :"
    dotnet .\webapi.dll environment=staging

huangapple
  • 本文由 发表于 2023年3月31日 18:39:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75897574.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定