views:

399

answers:

3

I have a source XML file that is used to create C# files that are then compiled as part of a project.
Currently I have a BeforeBuild target that runs my XML to C# converter.
The problem is that by the time the BeforeBuild step is run the old files appear to have been stored by the build system so the new files are ignored.

How can I get around this? It seems that Transforms would be the way but they are limited in what they can do.

A: 

Well we have something similar-ish here. We gen a .cs off an xml file using a .tt. Both files are part of a specific csproj. Going properties->BuildEvents on the csproj gives this little snippet in the Pre-build event command line:

del "$(ProjectDir)MyCsFile.cs"
copy /b /y "$(ProjectDir)\MyXmlFile.xml" "$(TargetDir)"
"$(ProjectDir)tt.bat" "$(ProjectDir)MyTemplateFile.tt"

No idea if that's of any use to you, I hope it might suffice as a last chance workaround.

Quibblesome
A: 

I think you need to show us a little of your rule/build file. You should have a rule/dependency for the cs file that has the xml as the dependency.

I am not sure what you mean by "stored by the build system"

Check your rules carefully for errors/omissions.

Tim
+1  A: 

I guess your "stored by the build system" can be translated as the ItemGroup containing the .cs files you wish to compile is generated when the msbuild file is read, as opposed to when your compile target is executed. You have several options:

  1. <CreateItem> see CreateItem task
  2. <Output> see Output element

I hope this helps.

Bas Bossink