TFS Build Workflow Change Folder/File Attributes From Read-Only to Read/Write?

后端 未结 2 1275
清酒与你
清酒与你 2021-01-24 22:39

In one of our web applications, it is required that some HTML pages be editable in a GUI interface we created for the user. Unfortunately, the interface directly reads/writes f

相关标签:
2条回答
  • 2021-01-24 23:15

    How about adding a custom code activity that runs post-deploy to update the attributes of the files to not FileAttributes.Normal? This activity should probably run on the controller at the end of the build.

    You might want to check out Ewald Hofman's series of build customization. Your build service account will likely have the correct permissions to update the deployed file attributes.

    Hope this helps.

    0 讨论(0)
  • 2021-01-24 23:28

    I bumped on this & assume it's connected with this question as well.

    What @Duat suggests has worked for me, within the scope of the Build-Agent server. Yet, in your other question, you mention a net-drive - so I suppose you 're talking about file(s) residing either in the drop location of your build, or on the target computer where MSBuild/MSDeploy deploys your solution.

    I will advance with the first assumption (so, we 'll focus on Drop Location), but it should be similar to handle the matter in either case.
    The idea bases on a strategically placed 'xcopy'. ('xcopy' per default resets all file attributes into read-write during execution)
    The first step is to construct a custom activity that sets the files you need into read-write. A quick first draft of the activity can be this (it's meant to change the attributes of a file, not a dir):

    namespace BuildTasks.Activities
    {
        using System;
        using System.Activities;
        using System.IO;
        using Microsoft.TeamFoundation.Build.Client;
    
        [BuildActivity(HostEnvironmentOption.Agent)]
        public sealed class MakeFileWriteable : CodeActivity
        {
            [RequiredArgument]
            public InArgument<string> FilePath
            {
                get;
                set;
            }
    
            protected override void Execute(CodeActivityContext context)
            {
                String filePath = FilePath.Get(context);
    
                //add exception handling 
    
                FileAttributes fileAttributes = File.GetAttributes(filePath);
                File.SetAttributes(filePath, fileAttributes & ~FileAttributes.ReadOnly);
            }
        }
    }
    

    The second step, now once you have MakeFileWritable in your build solution, is to change your build definition from this
    enter image description here
    into something like this
    enter image description here

    The file in MakeFileWriteable should be from within the BuildAgent and is the FROMFILE in the InvokeProcess that follows:
    enter image description here
    TOFILE is where the file should land.
    Remember to set the "/Y" in the arguments, since you 'll be overwriting the file.

    0 讨论(0)
提交回复
热议问题