locked
AssemblyInfoTask: Overwriting read-only files? RRS feed

  • 问题

  • Hey All,

    I just found the AssemblyInfoTask for MSBuild and it's almost exactly what I need! I'm creating a build system for our product using CruiseControl.net where the source is fetched from SourceSafe before a build. I've got a version generated by CC being passed into the MSBuild engine, and in testing, being written to the assemblies via the AssemblyVersion property.

    The problem I'm encountering is that when the files are fetched from VSS, they are read-only. As a feature request, could the task overwrite files regardless/undo the read-only attribute? Currently I'm either going to have to create a CC.net task to undo the attribute or alter the source code for the AssemblyInfoTask to handle it.

    Thanks!

    John

    2005年12月20日 17:20

答案

  • Cool...

    Good to know that you are finding the AssemblyInfo task useful.

    As an alternative, you can "tweak" your build process to do the work.  That might give you more flexibility - i.e. have a pre-build that flips the attribs on the file, and a post-build that flips it back.  That way you don't have to change the behavior of the task.

    Also, presumably you have one build machine that is responsible for checking out the AssemblyInfo.cs at some point during the day, updates the file and checks it back in, and then labels the entire source tree with the same version number?  If that is the case, then you might want to have the build machine exclusively perform these steps (based on an environment variable, or a property that is passed into the build indicating the machine's role / identity.

    Just throwing out thoughts.  Every build lab is different, and every developer workstation is different.  At the very least, worth discussing!

    Faisal Mohamood
    Program Manager - MSBuild

     

    2005年12月21日 7:06
  • Hey Faisal,

    The AssemblyInfoTask rocks! It certainly made my day...I needed to accomplish exactly what it does.

    We aren't modifying assemblyinfo.cs in source control; just at build time. I've got it set up so that sending in the version as a property to MSBuild will change the version, but sending in nothing will do nothing (the build box uses the same scripts to build as our dev team).

    Thanks also for publishing the source code with it. For what it's worth, I made the following changes to support our specific case:

    • The undoing of the read-only attribute from above
    • Re-set the read-only attribute once done
    • Even prior to that, the first thing I do in the task is check that there actually is work to do (no params = no work) and return true from the task if there's nothing to do.

    Thanks again!
    John

    2005年12月22日 1:13

全部回复

  • Just in case anyone else is interested, this took 3 lines of code to fix. First thing in the constructor of AssemblyInfoWrapper, add the following lines:

    FileInfo info = new FileInfo(filename);
    if (info.IsReadOnly)
         info.IsReadOnly =
    false;

    Thanks!

    John

    2005年12月20日 17:56
  • Cool...

    Good to know that you are finding the AssemblyInfo task useful.

    As an alternative, you can "tweak" your build process to do the work.  That might give you more flexibility - i.e. have a pre-build that flips the attribs on the file, and a post-build that flips it back.  That way you don't have to change the behavior of the task.

    Also, presumably you have one build machine that is responsible for checking out the AssemblyInfo.cs at some point during the day, updates the file and checks it back in, and then labels the entire source tree with the same version number?  If that is the case, then you might want to have the build machine exclusively perform these steps (based on an environment variable, or a property that is passed into the build indicating the machine's role / identity.

    Just throwing out thoughts.  Every build lab is different, and every developer workstation is different.  At the very least, worth discussing!

    Faisal Mohamood
    Program Manager - MSBuild

     

    2005年12月21日 7:06
  • Hey Faisal,

    The AssemblyInfoTask rocks! It certainly made my day...I needed to accomplish exactly what it does.

    We aren't modifying assemblyinfo.cs in source control; just at build time. I've got it set up so that sending in the version as a property to MSBuild will change the version, but sending in nothing will do nothing (the build box uses the same scripts to build as our dev team).

    Thanks also for publishing the source code with it. For what it's worth, I made the following changes to support our specific case:

    • The undoing of the read-only attribute from above
    • Re-set the read-only attribute once done
    • Even prior to that, the first thing I do in the task is check that there actually is work to do (no params = no work) and return true from the task if there's nothing to do.

    Thanks again!
    John

    2005年12月22日 1:13
  • John,

        Can you elaborate how you are doing this part " I've got it set up so that sending in the version as a property to MSBuild will change the version". Are you like loading the AssemblyInfo.cs file and looking for the AssemblyVersion attribute and changing it or is there an easier way of doing it?

    Thanks,

    Surya

    2005年12月30日 7:07