Reputation: 2796
We have a VS2012 solution with a dozen or so C# projects in it. One of the C# projects makes use of a text file, which is converted to SQL by a separate C# tool we've written. We want to automatically invoke this TXT-2-SQL file conversion during a build whenever the TXT file has changed (Release and Debug build).
Furthermore, we'd like the Debug build to cause the SQL to be loaded into the local DB; ie, invoke one of our existing batch files, populate_db.bat, with the SQL filename as an argument (this just wraps the invocation of the mysql client and causes the SQL to be executed).
What's the best way to do this?
Upvotes: 3
Views: 2082
Reputation: 2796
From my own research, I've found the following choices:
Target + Execs - Add custom target nodes to our existing csproj:
<Target Name="TXT2DB"
AfterTargets="Build"
Condition=" '$(Configuration)' == 'Debug' "
Inputs="MyTextFile.txt"
Outputs="MySqlFile.sql"
Label="TXT2DB" >
<Exec Command="$(ProjectDir)\Tools\txt2sql\txt2sql.exe MyTextFile.txt MySqlFile.sql" />
<Exec Command="populate_db.bat MySqlFile.sql" />
</Target>
Post Build Events - use post build events. Mentioned for completeness, but discarded b/c it happens in both debug and release, and doesn't seem to be sensitive to a TXT file change.
Currently, we've selected #4 as the easiest to impl and maintain solution, and satisfies all the requirements.
Upvotes: 6