简体   繁体   English

C# - 发布配置文件中的自定义环境变量

[英]C# - Custom Environment Variable in Publish Profile

We are using .Net Core 3.1 and we have multiple publish profiles.我们正在使用.Net Core 3.1并且我们有多个发布配置文件。 In each there is每一个里面都有

<EnvironmentName>Development</EnvironmentName>

or Production etc. I would like to add another variable which is named by me.或生产等。我想添加另一个由我命名的变量。

Unfortunately you can not register any other environment variables when you publish, only the EnvironmentName.不幸的是,您在发布时无法注册任何其他环境变量,只能注册 EnvironmentName。

The same thing can be achieved like同样的事情可以实现

dotnet publish -c Debug -r win-x64 /p:EnvironmentName=Development

if you want to clear out your csproj file.如果你想清除你的 csproj 文件。

Coming back to environment variables, I can see two solutions:回到环境变量,我可以看到两种解决方案:

  1. Move to a docker solution and pass the environment variables into your container.移至 docker 解决方案并将环境变量传递到您的容器中。 That is pretty easy and straight forward.这非常简单直接。 Link to docker documentation链接到 docker 文档
  2. Add a powershell script that will set the variables in the server.添加将在服务器中设置变量的 powershell 脚本。

You can only set the environment variable in your publish profile.您只能在发布配置文件中设置环境变量。 You can name it anything you want.您可以随意命名。 To set other variables you would have to use web.config transformations .要设置其他变量,您必须使用web.config transformations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM