Fix to work with new NuGet PackageReference style in VS2017
See original GitHub issueHi, we were using RazorGenerator.MsBuild in our csproj for a long time without any problem. After we switch csproj to new NuGet RestoreProjectStyle=PackageReference in VS2017 RazorGenerator failed during build.
One important note. We don’t use Custom Tool at cshtml file properties (RazorGenerator) and also we don’t use directives at top of cshtml files (@* Generator : MvcHelper .... *@
).
Problem is in RazorGenerator.Core.IsMvcProject method which works only for old NuGet package reference style: <Reference Include="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"><HintPath>..\..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll</HintPath> <Private>True</Private></Reference>
.
For new one it returns False and thats the problem:
<PackageReference Include="Microsoft.AspNet.Mvc"><Version>5.2.3</Version></PackageReference>
There is easy workaround for this. We just add razorgenerator.directives
file to root directory of your cshtml files with content like this: RazorVersion: 3 Generator: MvcView
and build works again.
PS: RazorVersion: 3 is used for Microsoft.AspNet.Mvc version 5. For version 4 use RazorVersion: 2
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:15 (7 by maintainers)
Top GitHub Comments
@bednart We also found we could also work around this by adding a simple XML comment to our .csproj:
Which will let RazorGenerator return the correct values (for us) from
IsMvcProject
.I now have RazorGenerator’s Custom Tool working in VS2019 - phew. The VSIX is also compatible with VS2015 and VS2017.
Caveats: