Question

I've added a pre-build action for an ASP.NET web control (server control) project, that runs jsmin.exe on a set of Javascript files. These output files are part of the source control tree and are embedded into the assembly.

The problem is when the pre-build runs, jsmin can't write the file as it's readonly. Is it possible to check the file out before hand? Or am I forced to set the file's attributes in the command line.

Any improved solution to the problem is welcome.

Update One small issue with Mehmet's answer -you need to prepend the VS directory:

"$(DevEnvDir)tf" checkout /lock:none "$(ProjectDir)myfile" 
Was it helpful?

Solution

If you're using Team Foundation Server, you can use team foundation command line utility (tf.exe) to check out the file(s) during pre-build and then check them back in during post-build. If you're using something else for source control, you can check if they have a command line tool like tf.exe.

OTHER TIPS

If you do not want to check the files in as part of the build (which you normally wouldn't for this sort of thing) then I would simply set the attributes of the .js files before running jsmin on them. The easiest way of setting the files read-writeable is to use the the Attrib task provided by the MSBuild community extensions. The same community extensions also provide a JSCompress task for easily calling JSMin from MSBuild.

Therefore you'd have something like the following (not tested):

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />

<!-- rest of TFSBuild.proj file -->

<Target Name="AfterGet">    
  <Message Text="Compressing Javascript files under &quot;$(SolutionRoot)&quot;." />   
  <CreateItem Include="$(SolutionRoot)\**\*.js">
    <Output TaskParameter="Include" ItemName="JsFiles"/>
  </CreateItem>
  <Attrib Files="@(JsFiles)" ReadOnly="false"/>
  <JSCompress Files="@(JsFiles)" />
</Target>

Note that by modifying the files after getting them may well cause issues if you tried to move to an incremental build.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top