2
votes

I have a build process on Azure DevOps that I have been building successfully for awhile now.

Recently one of my developer added a page that contains the MVC library

using System.Web.Mvc

However, the build keeps failing now when I build it via the Azure DevOps build agent as part of our CI/CD process.

ClassName.cs(5,18): Error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

It compiles if I compile manually using Visual Studio 2017 on my own laptop or if I use the Visual Studio 2017 on the build machine where the Azure DevOps build agent runs.

The steps that I've tried to troubleshoot:

  • Ensure in my Project's NuGet, that I have Microsoft.Aspnet.MVC latest vesrion.
  • I've tried to reinstall Microsoft.Aspnet.MVC on the build
    machine through NuGet
  • I verified my project' default package
    management format is : Packages.config
  • I verified that my packages.config has < package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net472" />
  • I tried to reinstall all the package on my build machine by running Update-Package --reinstall command.
  • I verified that on the build agent machine I have the Microsoft.AspNet.Mvc folder and all of its dlls under repositoryPath -
    $(Solutiondir)/packages and globalPackagesFolder -
    $(UserProfile).nuget\packages

I'm running out of idea on why it compiles on Visual Studio manually but has error when I compile using the build agent through MS Build on x64 bits.

1
Does your build have a NuGet Restore step?Crowcoder
Yup, I do, just prior to the building steps of me *.slnFylix
Seems like it could be a variety of thingsCrowcoder
Hi, any update for this issue? If Elphas's reply is helpful please consider marking it as answer. It same issue persists please feel free to let us know :)LoLance

1 Answers

2
votes

I have tried to reproduce your bug by comparing two new ASP.NET Web Application (.NET Framework) projects, one created with an empty template and the other with the MVC template. The MVC project comes with the System.Web.Mvc reference and the empty one does not, so I have come up with additional troubleshooting steps while manually adding the reference to the empty project.

  • Make sure the project file that is failing to build includes a reference to the Microsoft.AspNet.Mvc package which includes a path (use your latest version)
    <Reference Include="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <Private>True</Private>
      <HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.4\lib\net45\System.Web.Mvc.dll</HintPath>
    </Reference>

You can copy this and it from a newly created MVC template. An implicit reference <Reference Include="System.Web.Mvc" /> will only work if build artifacts were generated before which could be a good reason for a build succeeding in development and failing in the build pipeline.

  • Clean the solution, close Visual Studio and delete all bin and obj folders to make sure your build is not succeeding because of previous ones and Visual Studio does not regenerate them.

  • Use the Developer Command Prompt to call msbuild.exe in the project folder, this will be a more similar environment to your build pipeline than building with Visual Studio