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

ⅰ亾dé卋堺 提交于 2019-12-20 04:38:43

问题


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 from a page on the server (also in the wwwroot). Another page on the server reads from it and just displays it.

What I have now done is changed our entire build process so that nothing is manual anymore and I am now using the build workflow with TFS/VS 2010 which is nice.

But TFS automatically puts everything in read-only mode when it deploys the code.

Is there a way to programatically (at any step in the process), change the attributes of a folder/file from read-only to read-write so that the web interface still works correctly?


回答1:


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.




回答2:


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


into something like this


The file in MakeFileWriteable should be from within the BuildAgent and is the FROMFILE in the InvokeProcess that follows:


TOFILE is where the file should land.
Remember to set the "/Y" in the arguments, since you 'll be overwriting the file.

来源:https://stackoverflow.com/questions/6713426/tfs-build-workflow-change-folder-file-attributes-from-read-only-to-read-write

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!