NuGet with RazorGenerator.MsBuild

Jan 14, 2014 at 4:46 PM
Hi, I have a project which uses RazorGenerator.MsBuild to compile the views into the assembly. This works nicely.

Now I need to create a NuGet package for my project. However when I run the the nuget pack command it copies the views into a content directory underneath my package. I noticed this was because the build action against the Views is set to Content. This seems like it's not needed to me.

I was wondering what's the best way to handle this?

Jan 14, 2014 at 4:58 PM
You could simply change the build action to None.
Jan 14, 2014 at 9:32 PM
Edited Jan 15, 2014 at 9:25 AM
Thanks but I can imagine when I create new views in the future I'll forget to do this occasionally. Is it possible to make this more automatic? Possibly with some kind of built event. I'm quite new to MsBuild so please bare with me.
Jan 14, 2014 at 9:37 PM
It might be possible with enough msbuild magic. Ideally, it would happen at the time the view is added, and not at build time.
Jan 15, 2014 at 9:26 AM
Thanks I guess I'll have to manually do this for the time being.
Mar 21, 2014 at 6:12 AM
This can be easily fixed by adding following target to the project file:
  <Target Name="BeforeBuild">
      <Content Remove="Views\**\*.cshtml" />
      <None Include="Views\**\*.cshtml" />
This will remove all views from content and adds them to group none.
Mar 21, 2014 at 9:39 AM
Thanks NightElfik I'll give this a go.
Jan 12, 2015 at 9:57 PM
I have this exact problem, but can't get that msbuild magic to do anything. I added it to the .csproj and it still compiles (I tried moving it around to several different places, tried removing the target and just putting the definitions in with the other ItemGroups--that didn't compile, so I knew it was paying attention). But when I try to install the package, it's trying to copy the views still. Did you ever get this working?
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
  <Target Name="BeforeBuild">
      <Content Remove="Views\**\*.cshtml" />
      <None Include="Views\**\*.cshtml" />
Jan 13, 2015 at 8:55 AM
@bussemac it's been a while since I looked at this. I believe I solved this by running the NuGet pack command against a .nuspec file and not the .csproj file. Here's an example of a .nuspec file (this is placed within the same directory as the .csproj file):
<?xml version="1.0"?>
<package >
        <description>Description here</description>
        <copyright>Copyright 2015</copyright>
            <dependency id="My.NuGet.Dependency.Here" />
        <file src="bin\Project.Name.dll" target="lib\net45" />