You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否通过VSTS的AWS CodeDeploy任务排除文件部署?.NET应用配置文件留存咨询

需求可行性分析

Absolutely, your requirement is completely feasible! This is a standard practice for .NET web application deployments, as .config files (like web.config or app.config) typically store environment-specific configurations—think database connection strings, API keys, or local settings—that shouldn’t be overwritten with every deployment. AWS CodeDeploy was designed to handle exactly this kind of file retention scenario, and you can absolutely implement it using the AWS CodeDeploy task in VSTS (now Azure DevOps).

如何通过VSTS的AWS CodeDeploy任务实现文件排除部署

There are a couple of straightforward ways to pull this off, depending on whether you want to handle exclusion at the build stage or directly within CodeDeploy’s configuration:

1. Use AWS CodeDeploy’s appspec.yml Configuration File

The appspec.yml is the core configuration file for AWS CodeDeploy, and it lets you explicitly define which files to include or exclude during deployment. Here’s how to set it up:

  • Create or update your appspec.yml file (make sure it’s in the root of your deployment package) with an exclude list targeting your .config files. For a Windows-based .NET app, the config might look like this:
    version: 0.0
    os: windows
    files:
      - source: /
        destination: C:\inetpub\wwwroot\YourWebApp
        exclude:
          - web.config
          - app.config
          - **/appsettings.config
    
  • When you run the VSTS AWS CodeDeploy task, it will read this appspec.yml and skip deploying any files listed in the exclude section. This ensures your server’s existing .config files remain untouched.

2. Exclude .config Files During the VSTS Build Stage

If you prefer to keep the .config files out of the deployment package entirely, you can exclude them during your build process:

  • DotNet Publish Task: Add the --exclude-files parameter to your publish command. For example:
    dotnet publish --configuration Release --exclude-files web.config,app.config
    
  • Archive Files Task: If you’re archiving your build output for deployment, use the "Exclude" field to specify .config files. You can use glob patterns like **/*.config to exclude all config files, or target specific ones like web.config.

3. Optional: Use CodeDeploy Hook Scripts for Advanced Retention

If you need more control (like backing up config files before deployment, or conditionally retaining them), you can use CodeDeploy’s hook scripts. For example, add a BeforeInstall hook in appspec.yml to back up your existing .config files to a temporary location, then restore them after deployment completes. This is overkill for basic exclusion, but useful for complex workflows.

Just make sure your VSTS AWS CodeDeploy task is pointed at the correct deployment package (either the one with the configured appspec.yml or the build output where .config files were excluded), and you’re good to go.

内容的提问来源于stack exchange,提问作者Yasmin AbdelGhaffar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:55:10