question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix to work with new NuGet PackageReference style in VS2017

See original GitHub issue

Hi, 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:open
  • Created 5 years ago
  • Reactions:5
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
declspeccommented, May 8, 2019

@bednart We also found we could also work around this by adding a simple XML comment to our .csproj:

<!-- System.Web.Mvc, Version=5 -->

Which will let RazorGenerator return the correct values (for us) from IsMvcProject.

0reactions
daipluspluscommented, Mar 4, 2021

I now have RazorGenerator’s Custom Tool working in VS2019 - phew. The VSIX is also compatible with VS2015 and VS2017.

Caveats:

  • The code in RazorGenerator to load the “v1” (ASP.NET 3.5, .NET Framework 2.0-3.5), and “v2” (ASP.NET 4.0) versions of the Razor libraries are… convoluted. I think it would be prudent to simply cut-off those vestigal versions now, no?
  • No support for ASP.NET Core’s version of Razor. This is increasingly more important so I’ll see what I can do.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrate from packages.config to PackageReference
Open the Package Manager UI - Right-click on References and select Manage NuGet Packages... · Open the Package Manager Console - From Tools...
Read more >
PackageReference in project files - NuGet
NET Framework projects support PackageReference, but currently default to packages.config . To use PackageReference, migrate the dependencies ...
Read more >
Adding NuGet package reference doesn't refresh References
1. Open/create project in VS 2017 using .Net Framework. Ensure VS is set to use PackageReference. · 2. Add NuGet package · 3....
Read more >
How to solve the error "Must use PackageReference"?
Uninstall any NuGet packages related to Microsoft.Windows.SDK.Contracts , set PackageReference as default format, re-install all packages using ...
Read more >
Managing Dependencies in .NET: .csproj, .packages.config ...
In .NET Core, when a new NuGet package is referenced, that is captured in the .csproj in the PackageReference section. In some project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found