15

I've found that in the .csproj for an ASP.NET MVC project there is the following target:

<Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
</Target>

This examines the MvcBuildViews bool property in the .csproj which if set to true gets the build to check the views.

I use NAnt to build my app for deployment, is it possible to get this target to run from the msbuild command line without having to modify the csproj? (I want it to be run only on deploy, not every build as its slow + resharper catches it in VS anyway)

If not, how to i translate the above code to msbuild command line so i can modify my deploy script? Here's my current script:

<target name="Deploy" depends="init">
    <exec basedir="." program="${DotNetPath}msbuild.exe" commandline=" src/MyProject.Web/MyProject.Web.csproj /nologo 
  /t:Rebuild
  /t:ResolveReferences;_CopyWebApplication
  /p:OutDir=../../output/build/bin/
  /p:WebProjectOutputDir=../../output/build/
  /p:Debug=false
  /p:Configuration=Release
  /v:m"
    workingdir="." failonerror="true" />
    <call target="tests"/>
    <call target="compress-js"/>
    <call target="compress-css"/>
    <call target="rar-deployed-code"/>
  </target>

1 Answer 1

17

Setting the property MvcBuildViews to true should work.

<target name="Deploy" depends="init">
  <exec basedir="." program="${DotNetPath}msbuild.exe" commandline=" src/MyProject.Web/MyProject.Web.csproj /nologo 
    /t:Rebuild
    /t:ResolveReferences;_CopyWebApplication
    /p:OutDir=../../output/build/bin/
    /p:WebProjectOutputDir=../../output/build/
    /p:Debug=false
    /p:Configuration=Release
    /p:MvcBuildViews=true
    /v:m"
      workingdir="." failonerror="true" />
      <call target="tests"/>
      <call target="compress-js"/>
      <call target="compress-css"/>
      <call target="rar-deployed-code"/>
</target>
Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant, I didn't know you could do that, but then looking at my own script I'm clearly already doing it for a several other properties! doh!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.