This project is read-only.

using razor generator in my builds

Aug 6, 2011 at 1:40 AM

is there a way to run the tool from the command line so I can incorporate it into the build process?

Coordinator
Aug 6, 2011 at 1:48 AM

Right now there isn't, though conceivably it could be made to work.

However, I'm not sure I understand why you'd want to do that. The general guidance here is the same as for other VS generators (like T4 or EF edmx files): the generated files gets committed to the project, so there is no need to generate it at build time. It only needs regeneration when the cshtml file changes.

One problem if you don't do this is that when you first open your solution, everything will look broken until you build because those files won't be there.

It may just be that I don't understand your scenario!

Aug 6, 2011 at 2:01 AM

We are using the tool on cshtml files is a project that we are using for email templates.  We have a bunch of cshtml files in a project and it would be easier if we could set up a build event that would run the tool for each cshtml file in the project instead of having to run the tool for each file.

 

We most likely will be checking in the genned files as well.  So its not an issue of it not working as it is now, its just we are trying to make it a little easier to use.

 

One other question:

In order to use the tool do we need to install the extension or can we use the assembly on its own in any way?

Coordinator
Aug 6, 2011 at 2:07 AM

I see. We actually have an work item to help make this easier. Most likely, it'll be via some PowerShell command you run in the nuget window.

You need the extension for VS to be able to turn cshtml files into .cs files. But once generated, at runtime, there is no need for the extension.

Coordinator
Aug 8, 2011 at 4:29 PM

Have you tried using the msbuild task for this? I don't think we have a package for it as yet, but you should be able to pass in all cshtml files for it and have it build temporary cs files from it.

Aug 8, 2011 at 4:36 PM

I have not tried that.  Is there any documentation on this?  or a sample of how to call it?

Coordinator
Aug 8, 2011 at 5:24 PM

I pushed a package named RazorGenerator.MsBuild v1.0 to the NuGet feed, Could you install the package and add a reference to the targets file in your project (I'll add some PS magic to automate this soon)

<Import Project="..\packages\RazorGenerator.MsBuild.1.0\tools\RazorGenerator.targets" />

This would compile all chstml files in a project prior to building the project.

Aug 11, 2011 at 1:16 PM

I installed the RazorGenerator.MsBuild package but got an error after adding the line above to my project file:

packages\RazorGenerator.MsBuild.1.0\tools\RazorGenerator.targets(16,9): error : The parameter 'PhysicalDirectory' is invalid.
packages\RazorGenerator.MsBuild.1.0\tools\RazorGenerator.targets(16,9): error : Parameter name: PhysicalDirectory

Any suggestions?

Coordinator
Aug 11, 2011 at 5:46 PM

That's odd. I don't see any references to the term anywhere in my targets file, the msbuild and generator project or in the Razor parser code. Would you mind attaching a sample project where this repros?

Aug 12, 2011 at 11:15 AM
Edited Aug 12, 2011 at 11:18 AM

Sure, you can download a simple project from http://www.handfast.se/downloads/RazorGeneratorMsBuildTest.zip

I created a new mvc 3 project and added the target in the project file. I've tested to place the project in the "My Documents" folder and directly under D:\

I am running the build inside Visual Studio with elevated mode.

Edit: I get the same error running in the studio command prompt and running msbuild there.

Coordinator
Aug 12, 2011 at 10:24 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Aug 14, 2011 at 6:47 PM

Thank you! It is now compiling. But I've discovered another issue with areas. See the issue here.