Templating: Question: Skip Pre/Post Build Steps When Developing Template

Created on 17 Aug 2017  路  3Comments  路  Source: dotnet/templating

I want to include JS build steps in the template csproj but do not want them to execute during development. For example, maybe I would like the template project to have the following pre-build task:

echo "Building client..."
(cd ./Client && ember build --output-path="../wwwroot")
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="echo &quot;Building client...&quot;&#xD;&#xA;(cd ./Client &amp;&amp; ember build --output-path=&quot;../wwwroot&quot;)" />
</Target>

This seems to work fine until I introduce the vsix project and now it takes msbuild quite a long time to build and sometimes even hangs indefinitely on PackTask. So, I was wondering if there is some conditional that can be used to prevent these tasks from running during development? Ideally they would only run in projects created by the TE.

Most helpful comment

@jaredcnance - we don't have any specific development conditionals built into the template engine. But there are some potential workarounds that will do what I think you're suggesting. How about this:

<!--#if (1 == 1)
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="echo &quot;Building client...&quot;&#xD;&#xA;(cd ./Client &amp;&amp; ember build --output-path=&quot;../wwwroot&quot;)" />
</Target>
#endif-->

Using the template engine's block comment conditional syntax for proj files, that piece of content is commented out in your dev version of the template. But for created instances of the template, the condition evaluates to true, the conditional-comment goes away, and the generated csproj file has the content uncommented.

All 3 comments

@jaredcnance - we don't have any specific development conditionals built into the template engine. But there are some potential workarounds that will do what I think you're suggesting. How about this:

<!--#if (1 == 1)
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="echo &quot;Building client...&quot;&#xD;&#xA;(cd ./Client &amp;&amp; ember build --output-path=&quot;../wwwroot&quot;)" />
</Target>
#endif-->

Using the template engine's block comment conditional syntax for proj files, that piece of content is commented out in your dev version of the template. But for created instances of the template, the condition evaluates to true, the conditional-comment goes away, and the generated csproj file has the content uncommented.

@seancpeters that sounds like exactly what I'm looking for. Thanks!

@seancpeters that is a neat trick, thanks for posting that. I've created an issue in the samples repo so that we can add a sample of this.

@jaredcnance can we close this issue?

Was this page helpful?
0 / 5 - 0 ratings