Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not install package 'Microsoft.AspNet.Razor 3.2.3' in Visual Studio 2015 Nuget package manager

I tried the following:

  1. I am trying to open a code set created in VS 2010 (pluralsight exercise) in VS Community 2015.

  2. The System.Web.Mvc reference was showing up with an error due to which the code won't compile. I tried to update the NuGet Microsoft.AspNet.MVC to current version - 5.2.3 and got the below error:

Could not install package 'Microsoft.AspNet.Razor 3.2.3'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

  1. I removed the code set and re-tried the above steps and update the NuGets incrementally only till the following and successfully compile the solution.

Microsoft.AspNet.MVC v4.0.40804

Microsoft.AspNet.Razor v2.0.30506

Microsoft.AspNet.Webpages v2.0.20710

I would like to know how the NuGets can be updated to their latest stable version.

like image 435
MuKa Avatar asked Jun 11 '17 15:06

MuKa


People also ask

How to Install NuGet packages in Visual Studio?

Install packages from NuGet.orgSelect Package Manager, and then copy the Install-Package command. In Visual Studio, select Tools > NuGet Package Manager > Package Manager Console to open the package manager console. Paste the command into the Package Manager Console and then press Enter.

What is NuGet package Manager in Visual Studio?

NuGet is a package manager that delivers compiled source code (DLLs) and other files (scripts and images) related to code. A NuGet package takes the form of a zip file with the extension . nupkg. This makes adding, updating, and removing libraries easy in Visual Studio applications.


1 Answers

AFAIK Microsoft.AspNet.Mvc 5.2.3 & Microsoft.AspNet.Razor 3.2.3 packages contains only .NET 4.5 assemblies, and hereby can't be installed on any project which has targetFramework=4.0 in web.config file even they're succeeded to add inside Package Manager Console.

If you're willing to change target framework version, edit targetFramework attribute value on both compilation & httpRuntime element in your project to use .NET 4.5 assemblies, or use project properties => Application => Target framework => .NET Framework 4.5:

<compilation targetFramework="4.5">...</compilation>

<httpRuntime targetFramework="4.5" />

NB: The latest compatible Razor engine version for Microsoft.AspNet.Mvc 4.040804 is 2.0.30506.0. Unfortunately as of now package's metadata doesn't have any info for supported target frameworks, hence you need to find out which packages fit to your project by yourself.

Related issue:

Dependencies of .NET Framework (Issue #878)

like image 61
Tetsuya Yamamoto Avatar answered Oct 16 '22 20:10

Tetsuya Yamamoto