2

This is an older project that I'm trying to spin up for the first time. I am getting this error:

Could not load file or assembly 'Microsoft.Web.Infrastructure, 
Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of 
its dependencies. The system cannot find the file specified

MVC4 (dotnet 4.5) application on VS2017.

I came across this S/O post but am unable to fully try the accepted answer as the Copy Local continues to change to back to False when I try to save the changes. Additionally, this other S/O post seemed to indicate that I should not be tampering with Copy Local properties so that behavior preventing me from setting Copy Local to True appears to be deliberate (or perhaps indicate the "assembly is found in the global assembly cache".

Why can't I set the Copy Local field? Any ideas on how I can try updating the Copy Local to True in VS2017?

mche
  • 616
  • 10
  • 16

5 Answers5

7

Experienced a similar issue on new Windows 10 machine on VS2015 with an existing older project. Package Manager 3.4.4. Restore packages enabled.

The restore doesn't seem to work as expected. Had to run the following on the Package Manager Command line

Update-Package -ProjectName "YourProjectName" -Id Microsoft.Web.Infrastructure -Reinstall

Change the above command to include the "-Version" option to target a specific version if you need to. Leaving out -Version and -Reinstall will update the package to the latest version. This added the following lines to my solution file which the restore did NOT do.

<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
  <Private>True</Private>
</Reference>

Just adding the above elements to the ItemGroup section in my project file ALSO solved the issue provided that ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll exists.

Easier to just do the -Reinstall but good to understand what it does differently to the package restore.

It's possible previous versions of the package manager did not add the above changes to the solution file when it was originally added and this is now needed.

Rohan
  • 578
  • 8
  • 12
1

Manually review each .csproj file and make sure you have the right MVC 4 libraries installed.

<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.20710.0\lib\net40\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\Microsoft.AspNet.Razor.4.0.20715.0\lib\net40\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\Microsoft.AspNet.WebPages.4.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>

Do note that MVC 4 targets .NET Framework 4.0, but .NET Framework 4.5 is an in-place upgrade so it is possible for your application to target .NET Framework 4.5 as long as it is installed on the dev machine. There are no net45 targets in the MVC 4 NuGet packages, but your application can still consume them.

You should also be able to change the CopyLocal setting by hand editing the .csproj file, but I am not sure how that is related to your question.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
0

It's likely a missing package. You can run the following to restore the dependencies:

nuget restore

If that doesn't work, try to install the package using the following:

Install-Package Microsoft.Web.Infrastructure -Version 1.0.0 
  • I think `dotnet restore` is only a dotnet-core command, no? And the PM-cmd doesn't run, but indicates it already exists in the project. – mche Jan 31 '18 at 00:20
  • Apologies, I've been working too much with NET Core recently. It's `nuget restore` in this case. I've updated the answer to reflect this – HarryGwinnell Jan 31 '18 at 00:22
0

In my case, I removed the folder Microsoft.Web.Infrastructure.1.0.0.0 from packages folder. So, works fine!

0

I just used the "Manage Nuget Packages for Solution" or "...Project", clicked the "Browse" tab and searched for "Infrastructure" and it was the top option. Clicked install and the project worked.

William T. Mallard
  • 1,562
  • 2
  • 25
  • 33