Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
You can create your own custom pre-generation build logic by utilizing the CodeSmith Generator Task within MSBuild. MSBuild tasks help manage the build process within your Visual Studio projects.

Why would I want to roll my own when you integrate it with Visual Studio?

...

An MSBuild target file is used to define your own tasks during the build process. CodeSmith Generator ships their own targets file which You can install the CodeSmith.Generator.Task NuGet package which defines all the capabilities of using generating CodeSmith Generator Projects during the generation process. The CodeSmith.NuGet package contains a targets file that defines how to use the Generate BuildAction from your Generate Items and also defines how to call CodeSmith with your CodeSmith Generator Project file and run the generation process.This file can be found at the following location: C:\Program Files\MSBuild\CodeSmith\CodeSmith.targets or C:\Program Files (x86)\MSBuild\CodeSmith\CodeSmith.targets


Info
When you set the BuildAction to Generate in Visual Studio, you're actually using the CodeSmithGenerate Target and set the project item to use the Generate Build Task.

...

Code Block
languagehtml/xml
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003 ">
   ...
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath)\CodeSmith\CodeSmith.targets" />
   ...
<Project>

Generating a Generator Project

...

Code Block
languagehtml/xml
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003 ">
   ...
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath)\CodeSmith\CodeSmith.targets" />
 
  <Target Name="BeforeBuild" Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <CodeSmith ProjectFile="GenerateMetaData.csp" />
  <Target>
   ...
<Project>

...