使用END特定应用程序部署Web应用程序

发布于 2025-01-31 06:39:38 字数 1575 浏览 4 评论 0 原文

我目前正在部署一个用于生产目的的应用程序设置的Web应用程序,用于测试目的。 在部署过程中,如何用生产或测试的内容替换appsetting.json?

要部署我使用IIS Web应用程序管理和IIS Web应用程序部署。

我目前要做的是每次将某些东西推到Main时,我都设置了Azure来触发一个i,

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  testConfiguration: 'Test'
  prodConfiguration: 'Production'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(testConfiguration)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(prodConfiguration)'

- task: DotNetCoreCLI@2
  inputs:
   command: 'publish'
   publishWebProjects: true
   zipAfterPublish: true
   arguments: '--output $(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

然后使用Drop中创建的伪像用于部署目的。 当我想部署到测试或生产环境时,就会发生问题。

解决方案本身在appsetting.json上具有A转换。 但是,位于Drop文件夹中的内容仅是发布的产品构建,而不是测试和产品。

我如何在Drop文件夹下包括两个?

因此,当我通过部署管道发布时,可以指定我要部署测试构建或构建?

I am currently deploying an web application on which I have an appsetting for production purposes and one for test purposes.
how do i during deploy replace the appsetting.json with the content of the production or test?

to deploy i use IIS web app manage and IIS web app deploy.

What I currently do is everytime something is pushed to main, I have setup Azure to trigger an

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  testConfiguration: 'Test'
  prodConfiguration: 'Production'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(testConfiguration)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(prodConfiguration)'

- task: DotNetCoreCLI@2
  inputs:
   command: 'publish'
   publishWebProjects: true
   zipAfterPublish: true
   arguments: '--output $(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

I then use the artifact created in drop to for deploy purposes.
The problem occur when I want to deploy to either my test or production environment.

The solution itself has an a transform on the appsetting.json, namely the appsetting.Test.json and appsetting.Production.json
but what is located in the drop folder is only the prod build published, and not both test and prod.

How do i include both under the drop folder?

So when I release it via the deploy pipeline can specify that I want to deploy the test build or prod build?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

愁杀 2025-02-07 06:39:38

您是否尝试过使用 Azure应用服务设置任务

Have you tried using the Azure App Service Settings task?

疯狂的代价 2025-02-07 06:39:38

如果您不需要可变替换,那么也许您可以拥有2份JSON ONE的副本和一个用于测试的副本,然后使用此处所述的复制任务: https://learn.microsoft.com/en.microsoft.com/en-en-us/azure/ devops/pipelines/tasks/distility/copy-files?view = azure-devops& amp; tabs = yaml

您可以在部署yaml中添加副本,并根据阶段使用所需的文件。此复制任务后,您可以添加您的部署任务。

If you do not want variable substitutions then maybe you can have 2 copies of the json one for prod and one for test and then use a copy task as described here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml

You can add the copy in your deploy yaml and use the file you need based on the stage. After this copy task you can add your deploy task.

掩饰不了的爱 2025-02-07 06:39:38

如果 appSetting.test.json 不包含在 drop 文件夹中的问题,请在.csproj:

<ItemGroup>
   <None Include="appsettings.Test.json" CopyToPublishDirectory="Always" />
</ItemGroup>

If the issue that the appsetting.Test.json not include in your drop folder, so add next section into your .csproj:

<ItemGroup>
   <None Include="appsettings.Test.json" CopyToPublishDirectory="Always" />
</ItemGroup>
森林很绿却致人迷途 2025-02-07 06:39:38

*。*。json 文件中的 appsettings。如果您为此而努力,则需要将有关 csproj 文件的更多详细信息包含在问题中。

部署到IIS后,请确保您设置 aspnetcore_environment 环境变量 测试如果您在测试环境上,以便将应用正确的配置。

我也有类似的答案,专门涉及使用这种切换环境的方式:。净核心3.1工人服务 - 在发布上设置环境名称

Instead of transforming the appsettings.*.json files into a single appsettings.json file during the solution build, make sure both original files are included in the drop folder. If you struggle with that, you need to include more detail about your csproj file into the question.

Upon deployment to IIS, make sure you set ASPNETCORE_ENVIRONMENT environment variable to test if you are on the test environment so that the correct configuration will be applied.

I also have a similar answer that deals specifically with using this way of switching environments: .NET Core 3.1 Worker Service - set EnvironmentName on publish

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文