locked
Views Compiling in ASP.NET MVC RRS feed

  • Question

  • User-118859203 posted

    Hi guys,

    I have msbuild task to compile the views. But I can see if there are compile time errors at well... compile time error. Any suggestions? Thanks

    Sunday, January 13, 2019 5:23 AM

Answers

  • User-552477072 posted

    Hi there,

    I would recommend the RazorGenerator nuget package. That way your views have a .designer.cs file generated when you save them and on top of getting compile time errors for you views, they are also precompiled into the assembly (= faster warmup) and Resharper provides some additional help as well.
    To use this include the RazorGenerator nuget package in you ASP.NET MVC project and install the "Razor Generator" extension under item under Tools → Extensions and Updates.

    We use this and the overhead per compile with this approach is much less. On top of this I would probably recommend .NET Demon by RedGate which further reduces compile time impact substantially.


    Please mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 13, 2019 5:43 AM
  • User-552477072 posted

    There is a better solution to your problem.

    I seemed to require this modified version of your Target block: <Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'" DependsOnTargets="CleanWebsitesPackage;CleanWebsitesPackageTempDir;CleanWebsitesTransformParametersFiles;"> <AspNetCompiler VirtualPath="temp" PhysicalPath="$(MSBuildProjectDirectory)" /> </Target>


    Please mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 13, 2019 6:27 AM
  • User-552477072 posted

    Hi 

    Your problem seems similar to the one talked about here: 

    http://blogs.msdn.com/aaronhallberg/archive/2007/07/02/team-build-and-web-deployment-projects.aspx 

    it seems the invocation of aspnet_compiler.exe fails to locate the binaries because the are not in the bin folder of the MVC project on the build machine. You can try with this. Hope will be no issue. Thanks.

    Please mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 13, 2019 6:54 AM

All replies

  • User-552477072 posted

    Hi there,

    I would recommend the RazorGenerator nuget package. That way your views have a .designer.cs file generated when you save them and on top of getting compile time errors for you views, they are also precompiled into the assembly (= faster warmup) and Resharper provides some additional help as well.
    To use this include the RazorGenerator nuget package in you ASP.NET MVC project and install the "Razor Generator" extension under item under Tools → Extensions and Updates.

    We use this and the overhead per compile with this approach is much less. On top of this I would probably recommend .NET Demon by RedGate which further reduces compile time impact substantially.


    Please mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 13, 2019 5:43 AM
  • User-118859203 posted

    Hi

    Its looking better but I had some old folders in my source control that were not visible in the Solution.

    Sunday, January 13, 2019 6:14 AM
  • User-552477072 posted

    There is a better solution to your problem.

    I seemed to require this modified version of your Target block: <Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'" DependsOnTargets="CleanWebsitesPackage;CleanWebsitesPackageTempDir;CleanWebsitesTransformParametersFiles;"> <AspNetCompiler VirtualPath="temp" PhysicalPath="$(MSBuildProjectDirectory)" /> </Target>


    Please mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 13, 2019 6:27 AM
  • User-118859203 posted

    The $(PublishDir) parameter did not point to the correct location. I had to use below code then only:

      <Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
        <AspNetCompiler Condition="'$(IsDesktopBuild)' != 'false'" VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
        <AspNetCompiler Condition="'$(IsDesktopBuild)' == 'false'" VirtualPath="temp" PhysicalPath="$(OutDir)\_PublishedWebsites\$(ProjectName)" />
      </Target>
    Sunday, January 13, 2019 6:42 AM
  • User-552477072 posted

    Hi 

    Your problem seems similar to the one talked about here: 

    http://blogs.msdn.com/aaronhallberg/archive/2007/07/02/team-build-and-web-deployment-projects.aspx 

    it seems the invocation of aspnet_compiler.exe fails to locate the binaries because the are not in the bin folder of the MVC project on the build machine. You can try with this. Hope will be no issue. Thanks.

    Please mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 13, 2019 6:54 AM