Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with XSLT in Visual Studio

In my C# client application, I use XSLT to transform XML into HTML.

I would like to be able to edit these files in place, without having to recompile the entire solution. I'm having trouble working out how to set up Visual Studio 2008 to allow this.

The problem is that the XSLT files must get copied to the output directory somehow. Currently this happens during the build process. (My XSLT files are set to "copy if newer".) The build process can take a few minutes, which seems excessive for making small tweaks to the HTML.

I could make my XSLT edits in the output directory itself, but the output directory is not under source control. I have accidentally wiped out my quick edits several times by building my solution.

I'd like to reduce the cycle time for debugging XSLT, while keeping my XSLT files under source control and preventing accidental overwrites.

Summary of Responses: It appears that the most practical approach for solving this problem -- given that Visual Studio doesn't have a nice way of doing it out of the box -- is to create a separate project that contains the content files. These files get copied to the output location when the project gets built. That way I don't have to compile the whole solution, just the one project with all the static information like XSLT, CSS, images, etc.

Several folks suggested using sync or batch copy tools, but while this would work for me personally, setting it up for the other members of the team too would be a lot of extra work.

like image 264
dthrasher Avatar asked Oct 21 '09 21:10

dthrasher


2 Answers

I am not entirely clear about your question, but you can instruct Visual Studio to copy the file from the solution to the output folder every time that you build.

Let me try to understand your scenario:

  • You have the XSLT files checked into source control along with your C# code. For example, if your project is in a folder called MyProj, then the XSLT files reside in MyProj/Templates
  • You want to be able to edit the xslt files in the Templates folder and submit those changes to source control just like you do with .cs or other files in your project.
  • You want a copy of your xslt files in the bin/Debug or bin/Release folder along with your executable.

If that is the case, add the XSLT files to your Visual Studio project. Then right click on them, open Properties, and set "Build Action" = "Content" and "Copy to Output Directory" = "Always". Whenever you build your project, the latest copy of the XSLT files will be placed in your bin/Debug or bin/Release directory.

like image 58
Anton Avatar answered Sep 23 '22 07:09

Anton


One approach is to include a C# Preprocessor Directive to point my XSLT load function to the solution directory when in debug mode, but the output directory when doing a release build.

Something like:

string viewFolder = AppDomain.CurrentDomain.BaseDirectory;

#if DEBUG
// Move up from /bin/debug
viewFolder = viewFolder + @"..\..\";
#endif

But that feels like a hack.

like image 26
dthrasher Avatar answered Sep 22 '22 07:09

dthrasher