如何使用Web Deploy迁移应用且不覆盖目标IIS现有站点?
Absolutely! You can migrate your apps using Web Deploy without overwriting existing sites/apps on the target server, and merge the contents of both servers' Default Web Site instances safely. Here are step-by-step approaches tailored to your scenario:
1. Migrate Individual Apps (Recommended for Precision)
Instead of migrating the entire Default Web Site from the source, export and import only the specific apps you need. This minimizes the risk of conflicting with target content:
Export from Source Server
Use the msdeploy command to export a single app under Default Web Site:
msdeploy -verb:export -source:appHostConfig="Default Web Site/YourTargetApp" -dest:package="YourTargetApp.zip"
Replace YourTargetApp with the name of the app you want to move.
Import to Target Server
On the target server, import the package while ensuring existing content isn't deleted:
msdeploy -verb:sync -source:package="YourTargetApp.zip" -dest:appHostConfig="Default Web Site/YourTargetApp" -enableRule:DoNotDeleteRule
- The
-enableRule:DoNotDeleteRuleflag is critical here: it tells Web Deploy to only add or update your migrated app and leave all existing target site/apps/files untouched. - If the app name already exists on the target, you can either rename the imported app (e.g.,
Default Web Site/YourTargetApp_Migrated) or use the-skiprule to avoid overwriting it (see section 2).
2. Merge Entire Default Web Site Contents (Preserve Target Existing Items)
If you need to sync the full Default Web Site from source to target but keep the target's existing content intact, use sync with targeted skip rules:
msdeploy -verb:sync -source:appHostConfig="Default Web Site" -dest:appHostConfig="Default Web Site",computerName=TargetServerName -enableRule:DoNotDeleteRule -skip:objectName=filePath,absolutePath="C:\inetpub\wwwroot\TargetExistingAppFolder" -skip:objectName=appHostConfig,keyAttribute="applicationPath",value="Default Web Site/TargetExistingApp"
Breakdown of key flags:
-enableRule:DoNotDeleteRule: Prevents deletion of any existing content on the target.-skip:objectName=filePath: Skips specific directories/files on the target you want to protect (replace the path with your actual target folder).-skip:objectName=appHostConfig: Skips specific existing apps on the target by their application path.
3. GUI Approach (IIS Manager)
If you prefer a visual interface instead of command line:
- Source Server: Right-click the app under
Default Web Site→Deploy→Export Application Package. Save the zip file. - Target Server: Right-click
Default Web Site→Deploy→Import Application Package. Select your zip file.- In the import wizard, under Select the import options, check the box for Do not delete extra files on destination (this maps to the
DoNotDeleteRule). - If the app name already exists on the target, you can choose to skip it or rename the imported app during setup.
- In the import wizard, under Select the import options, check the box for Do not delete extra files on destination (this maps to the
Critical Pre-Migration Checks
- Backup First: Always back up the target server's
Default Web Sitebefore making changes:msdeploy -verb:export -source:appHostConfig="Default Web Site" -dest:package="TargetDefaultSiteBackup.zip" - Validate Dependencies: Ensure the target server has matching .NET versions, IIS features, and any custom components (like certificates or third-party modules) required by your migrated apps.
- Database Sync: If your apps rely on databases, migrate those separately (e.g., SQL Server backup/restore or data sync tools) to avoid overwriting target databases.
内容的提问来源于stack exchange,提问作者Syntax Error




