1

Is it possible to write a pre-build event in Visual Studio 2010 that will change the build action from embedded resource to none for a file, or all files in a specific folder? Then, write a post-build event to change them back to embedded resource?

What would they look like? I have nothing posted so far because I don't even know what code I need to write for the events. Is it power shell? Command prompt?

Basically, I want to change the ccproj file from this:

<EmbeddedResource Include="Storage\Seeders\Sql\SqlA.sql" />
<EmbeddedResource Include="Storage\Seeders\Sql\SqlB.sql" />
<EmbeddedResource Include="Storage\Seeders\Sql\SqlC.sql" />

... to this:

<None Include="Storage\Seeders\Sql\SqlA.sql" />
<None Include="Storage\Seeders\Sql\SqlB.sql" />
<None Include="Storage\Seeders\Sql\SqlC.sql" />

... then back again in a post-build.

If doing this in a build event will not be simple, then I would accept that as an answer.

danludwig
  • 46,965
  • 25
  • 159
  • 237
  • I think you have to read up on VS project jibberish. :) – bzlm Jan 21 '12 at 13:33
  • @bzlm my searches so far have been unsuccessful. Hopefully someone can point me to some good resources. I do think this is a real question. I believe build scripts change the .ccproj file before and after the build, but not sure what code to change embedded resources it might look like. – danludwig Jan 21 '12 at 13:35
  • Well, if you compare two `.csproj` files, one with the build actions right, and one wrong, that might save you the googling. There is some stuff in the [BuildEngine namespace](http://msdn.microsoft.com/en-us/library/microsoft.build.buildengine.aspx) that lets you modify `.csproj` files, but I'm guessing you don't want to learn BuildEngine jibberish either. :) – bzlm Jan 21 '12 at 13:40
  • @bzlm I was not calling it jibberish because I do not want to learn it. I called it that because I'm not even sure what code I can use there. It looks similar to command line / powershell, both of which I do not have deep knowledge of. Thank you for the link I will check it out. – danludwig Jan 21 '12 at 13:45
  • What about the compare thing? Sounds like that would work. You can treat the .csproj file as text, or as XML, if you don't want the overhead of the `BuildEngine` stuff. – bzlm Jan 21 '12 at 13:46
  • For this specific scenario, it *could* work to simply backup the `.ccproj` in the pre-event, load it as XML, find the `EmbeddedResource` nodes using e.g. XPath, replace them with `None` nodes, and restore the `.ccproj~` in the post-event. No guarantees. :) – bzlm Jan 21 '12 at 14:00

0 Answers0