使用MSDeploy忽略文件属性?

时间:2011-07-28 22:28:25

标签: msdeploy

使用msdeploy进行同步操作时,MSDeploy检查以确定是否应同步文件的其中一项是文件上的属性(只读,存档等)。如果文件的两个副本之间的属性不同,则将同步该文件。有没有办法告诉MSDeploy在确定文件是否应该同步时忽略文件属性?

1 个答案:

答案 0 :(得分:3)

然而,不仅可以在命令行上。您必须构建自定义DeploymentRuleHandler,如下所示:

namespace CustomRuleHandlers
{
    using Microsoft.Web.Deployment;

    [DeploymentRuleHandler]
    internal class IgnoreFileAttributesRuleHandler : DeploymentRuleHandler
    {
        public override int CompareAttribute(DeploymentSyncContext syncContext, DeploymentObject destinationObject, DeploymentObjectAttribute destinationAttribute, DeploymentObject sourceObject, DeploymentObjectAttribute sourceAttribute, int currentComparison)
        {
            if ((destinationObject.Name.Equals("filePath", StringComparison.Ordinal)) 
                && destinationAttribute.Name.Equals("attributes", StringComparison.Ordinal))
            {
                return 0;
            }
            return currentComparison;
        }

        public override string Description
        {
            get { return "Ignores file attributes when determining if a file should be synched or not."; }
        }

        public override string FriendlyName
        {
            get { return "IgnoreFileAttributes"; }
        }

        public override string Name
        {
            get { return "IgnoreFileAttributes"; }
        }

        public override bool EnabledByDefault
        {
            get { return false; }
        }
    }

}

将其编译到程序集中(针对WebDeploy v2定位.Net 3.5!)并将程序集放入WebDeploy文件夹中的“Extensibility”子文件夹中(通常为C:\Program Files\IIS\Microsoft Web Deploy V2\Extensibility)。

然后,通过添加以下参数,从命令行运行msdeploy时,可以轻松利用自定义规则:

-enableRule:IgnoreFileAttributes

当然,同步操作需要在源计算机和目标计算机上都存在该程序集。

不幸的是,到达那里并没有更简单的方法!