开发者

Ignore file attributes with MSDeploy?

开发者 https://www.devze.com 2023-03-23 12:24 出处:网络
When using msdeploy to do a sync operation, one of the things that MSDeploy checks to determine if a file should be synced or not is the attributes on the file (readonly, ar开发者_如何转开发chive, etc

When using msdeploy to do a sync operation, one of the things that MSDeploy checks to determine if a file should be synced or not is the attributes on the file (readonly, ar开发者_如何转开发chive, etc.). If the attributes are different between the two copies of the file, then the file will be synced. Is there a way to tell MSDeploy to ignore file attributes when determining if a file should be synced or not?


It is possible, however, not merely on the command line. You'd have to build a custom DeploymentRuleHandler, like this:

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; }
        }
    }

}

Compile that into an assembly (targeting .Net 3.5 for WebDeploy v2!) and put the assembly into the "Extensibility" subfolder in the WebDeploy folder (normally, C:\Program Files\IIS\Microsoft Web Deploy V2\Extensibility).

Then, you can easily leverage your custom rule when running msdeploy from the command-line by adding this argument:

-enableRule:IgnoreFileAttributes

Of course, that assembly needs to be present on both, the source and the target machine, of a sync operation.

Unfortunately, there's no easier way of getting there!

0

精彩评论

暂无评论...
验证码 换一张
取 消