axel0r
axel0r

Reputation: 21

Modify C# Code BEFORE Compile in VS 2012

i've got a similiar Problem like the question here: Create MSBuild custom task to modify C# code *before* compile

I need to change .cs files before compilation. Of course i don't want them to get changed in place, because of the version control. I already figured out, that a Custom MSBuild Task might be the right choice to do the job.

Quote of the answer from the above question:

Create custom task that accepts the list of cs files to adapt prior to compilation

The solution seems clear and fine, but what i can't find out (all for Visual Studio 2012):

Thanks, it would be nice if somebody can help me with an example :-)

Upvotes: 2

Views: 1548

Answers (1)

mkko
mkko

Reputation: 362

A customer of mine asked me to replace some version and copyright information in some AssemblyInfo.cs files prior to the compile. I'm doing this via FileUpdate task with a RegEx in place. This of course leads to modified files. But that's no problem at all, just use the Exec task and run "svn revert" at the end of the build job:

    <Target Name="RevertModifications">
    <Message Text="reverting modifications..." />
    <Exec Command="svn revert -R $(RootDir)"/>
</Target>

Perhaps that might help?

Upvotes: 1

Related Questions