issue with PostSharp cannot find assembly for system.web.mvc, version=3.0.0.0 when no projects reference it

后端 未结 3 1520
不知归路
不知归路 2021-01-11 23:07

I\'m using PostSharp, and this was working fine. Recently, we upgraded some projects to the MVC version 5.2. Today, I loaded up an old project which was using version 4.0

相关标签:
3条回答
  • 2021-01-11 23:20

    This error is usually raised when some of the 3-rd party assemblies references older version of System.Web.Mvc. You have the binding redirect in your web.config, but you also need to tell PostSharp to use that configuration during build. You can do it by setting PostSharpHostConfigurationFile build property to the path of your *.config file.

    <PropertyGroup> 
      <PostSharpHostConfigurationFile>web.config</PostSharpHostConfigurationFile> 
    </PropertyGroup>
    
    0 讨论(0)
  • 2021-01-11 23:21

    Add the code below inside your [project].csproj file. To achieve this follow the steps:

    • Right-click in your Project;
    • Unload Project;
    • Then right-click in unloaded project and click Edit [project].csproj;
    • Look for a tag <Import Project of PostSharp;
    • Then add the following code right below the <Import Project .../> tag;
    • Then Reload the project;

    Code:

    <PropertyGroup>
        <PostSharpHostConfigurationFile>web.config</PostSharpHostConfigurationFile>
    </PropertyGroup>
    

    Your xml code should look something like:

    <Import Project="..\..\packages\PostSharp.4.0.42\tools\PostSharp.targets" Condition="Exists('..\..\packages\PostSharp.4.0.42\tools\PostSharp.targets')" />
    <PropertyGroup>
        <PostSharpHostConfigurationFile>web.config</PostSharpHostConfigurationFile>
    </PropertyGroup>
    
    0 讨论(0)
  • 2021-01-11 23:34

    Postsharp may be referencing MVC 3 internally. You can try a binding redirect in your web.config:

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
    
    0 讨论(0)
提交回复
热议问题