aspnet_compiler.exe not finding dependentAssembly

33 views Asked by At

We have an ASP.NET application that works fine when built and deployed with VS 2019. However, when I enable the Precompile mode, it has a problem finding a dependent assembly.

C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_compiler.exe -v \ -p C:\git\repo.xyz\MyProject\obj\Release\AspnetCompileMerge\Source -c C:\git\repo.xyz\MyProject\obj\Release\AspnetCompileMerge\TempBuildDir

C:\git\repo.xyz\MyProject\obj\Release\AspnetCompileMerge\TempBuildDir
Microsoft (R) ASP.NET Compilation Tool version 4.8.4084.0
Utility to precompile an ASP.NET application
Copyright (C) Microsoft Corporation. All rights reserved.

error ASPRUNTIME: Could not load file or assembly 'System.Web.Mvc, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I found this similar question, but none of those answers worked for me:

aspnet_compiler finding wrong version of System.Web.WebPages 1.0.0.0 instead of 2.0.0.0

We use nuget across the board for package configuration. We have chosen to use System.Web.Mvc 5.2.7, and have this configured in the project web.config:

<compilation defaultLanguage="c#" debug="false" targetFramework="4.8.0">
  <assemblies>
    ..
    <add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
    

NOTE: I have also tried Version=5.2.0.0.

Some packages have dependency references for earlier versions, so we have a dependentAssembly to cover those cases:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
      </dependentAssembly>

This works for a standard Build and Publish from VS. I just can't figure out why aspnet_compiler.exe is not reading/respecting the web.config in the project root (C:\git\repo.xyz\MyProject\web.config).

0

There are 0 answers