1

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?

Issa Fram
  • 2,318
  • 6
  • 32
  • 59

2 Answers2

3

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.

Duat Le
  • 3,576
  • 2
  • 17
  • 18
  • This is exactly what we also did at some point in the past. We had gotten help into writing the actual activity from [this](http://stackoverflow.com/questions/1202022/best-way-to-make-a-file-writeable-in-c) – pantelif Jul 19 '11 at 08:41
  • 1
    A custom activity is not needed. It is sufficient to have an "InvokeProcess" activity in your build template executing the "attrib" command with "-r /s *", for instance. – SKempken Nov 20 '14 at 13:45
1

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.

Community
  • 1
  • 1
pantelif
  • 8,449
  • 2
  • 30
  • 47