Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking a file out (TFS) for a pre-build action

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" 
like image 650
Chris S Avatar asked May 21 '09 10:05

Chris S


People also ask

How do I check a TFS file?

Right-Click In the File List, right-click the file you want to check in and select Source Control > Check In (for selected files) or Source Control > Project > Check In All (for all files in the project).

What is a build definition in TFS?

A build definition is the mechanism that controls how and when builds occur for team projects in TFS. Each build definition specifies: The things you want to build, like Visual Studio solution files or custom Microsoft Build Engine (MSBuild) project files.

How do I make a TFS build?

In the TFS web portal, open the desired project. Select Build and Release and then Builds in the Navigation bar. Click the +New button to create a build definition. On the Select your repository page, select the preferred repository type and Continue.


2 Answers

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.

like image 173
Mehmet Aras Avatar answered Oct 08 '22 05:10

Mehmet Aras


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.

like image 28
Martin Woodward Avatar answered Oct 08 '22 05:10

Martin Woodward