This project is read-only.

Use of generator in separate test project

Mar 14, 2013 at 12:39 PM
Hi

I was wondering whether it would be possible to use precompiled views in a unit test project only, without modifying anything in the mvc project?

Regards
Mar 14, 2013 at 6:02 PM
Generally, the generator is not limited to MVC projects, though I'm not sure I understand the question.
Mar 15, 2013 at 9:25 AM
I don't want to compile the views with the project itself, but only in my test project. In other words, i want to use precompiled views in my test project, but not in the project itself. Is this possible?

Thank you.
Mar 15, 2013 at 5:01 PM
Edited Mar 15, 2013 at 5:02 PM
If you're using the MsBuild package, it lets you specify the files to pre-compile
<ItemGroup>
    <RazorSrcFiles Condition=" '@(RazorSrcFiles)' == '' " Include="**\*.cshtml" />
    <RazorOutputFiles Include="@(RazorSrcFiles -> '$(RazorViewsCodeGenDirectory)%(RecursiveDir)%(Filename)%(Extension).cs')" />
</ItemGroup>
  1. Add the RazorGenerator.MsBuild package to your unit test project
  2. Add an itemgroup that points to the view files in your Mvc project
    <ItemGroup>
       <RazorSrcFiles Include="..\MyMvcProject\Views\**\*.cshtml">
           <Visible>False</Visible>
       </RazorSrcFiles>
    </ItemGroup>
    
    
This should get them to compile as part of your unit test project now.
Mar 18, 2013 at 12:58 PM
So I should just add
<ItemGroup>
   <RazorSrcFiles Include="..\MyMvcProject\Views\**\*.cshtml">
       <Visible>False</Visible>
   </RazorSrcFiles>
</ItemGroup>
to my unit test project file?

Which dll will include the views?