2014-10-01 20 views
8

Tôi đang sử dụng PostSharp, và điều này đã làm việc tốt. Gần đây, chúng tôi đã nâng cấp một số dự án lên phiên bản MVC 5.2. Hôm nay, tôi đã tải lên một dự án cũ đang sử dụng phiên bản 4.0 của MVC. PostSharp bắt đầu báo cáo một lỗi lạ trên xây dựng:vấn đề với PostSharp không thể tìm thấy lắp ráp cho system.web.mvc, phiên bản = 3.0.0.0 khi không có dự án tham chiếu nó

Error 17 Unhandled exception (3.1.42.0, 32 bit, CLR 4.5, Release): PostSharp.Sdk.CodeModel.AssemblyLoadException: Cannot find assembly 'system.web.mvc, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35'. [Version mismatch] 
============ PostSharp Assembly Loading Log =================== 
LOG: Finding the assembly with binding identity 'system.web.mvc, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35'. 
LOG: Found file 'C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll' with identity 'system.web.mvc, version=4.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35, processorarchitecture=msil'. 
LOG: Reference mismatch for 'C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll' [VersionMismatch]. 
LOG: Probing location 'C:\ProgramData\PostSharp\3.1.42\bin.Release\System.Web.Mvc.exe' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\ProgramData\PostSharp\3.1.42\bin.Release\System.Web.Mvc.dll' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\ProgramData\PostSharp\3.1.42\bin.Release\System.Web.Mvc.winmd' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\bin\Debug\System.Web.Mvc.exe' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\bin\Debug\System.Web.Mvc.dll' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\bin\Debug\System.Web.Mvc.winmd' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\obj\Debug\System.Web.Mvc.exe' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\obj\Debug\System.Web.Mvc.dll' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\obj\Debug\System.Web.Mvc.winmd' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Web.Mvc.exe' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Web.Mvc.dll' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Web.Mvc.winmd' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Web.Mvc.exe' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Web.Mvc.dll' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Web.Mvc.winmd' because this directory was explicitly added to the search path [File Not Found]. 
LOG: Looking in GAC for System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86. 
LOG: Looking in GAC for System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil. 
LOG: Looking in GAC for System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35. 
LOG: The assembly 'system.web.mvc, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35' was not found. 
=============================================================== 
    at PostSharp.Sdk.CodeModel.Domain.GetAssembly(IAssemblyName assemblyName, BindingOptions bindingOptions) 
    at PostSharp.Sdk.CodeModel.AssemblyRefDeclaration.^5YpB0scd(BindingOptions _0) 
    at PostSharp.Sdk.CodeModel.AssemblyRefDeclaration.GetAssemblyEnvelope(BindingOptions bindingOptions) 
    at PostSharp.Sdk.CodeModel.TypeRefDeclaration.GetTypeDefinition(BindingOptions bindingOptions) 
    at PostSharp.Sdk.CodeModel.TypeRefDeclaration.GetTypeDefinition() 
    at PostSharp.Sdk.CodeModel.CompareExtensions.DefinitionMatchesReference(INamedType definition, INamedType reference, BindingOptions options) 
    at PostSharp.Sdk.CodeModel.TypeRefDeclaration.^A9yFoe2uB3TC(ITypeSignature _0, BindingOptions _1) 
    at PostSharp.Sdk.CodeModel.CompareExtensions.DefinitionMatchesReference(IMethodSignature definition, IMethodSignature reference, BindingOptions options) 
    at PostSharp.Sdk.CodeModel.Binding.MethodSignatureComparer.Equals(IMethodSignature x, IMethodSignature y) 
    at System.Collections.Generic.Dictionary`2.FindEntry(TKey key) 
    at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value) 
    at ^/vWxD3eYDOIx.^wdkNIZCy[??0](^/fRRnkiTvxqu _0, ??0 _1, ^EyL1LQX01Ck8 _2, ^0RC0kpHqS6Uy _3, Dictionary`2 _4, Int32 _5, Int32 _6) 
    at PostSharp.Sdk.Binary.ModuleWriter.SetMemberSignatureIndex(MemberRefDeclaration _0, ^EyL1LQX01Ck8 _1, ^0RC0kpHqS6Uy _2) 
    at PostSharp.Sdk.Binary.ModuleWriter.WriteMemberRef(MemberRefDeclaration _0, MetadataToken _1) 
    at PostSharp.Sdk.Binary.ModuleWriter.GetMappedDeclarationToken(MetadataDeclaration _0) 
    at PostSharp.Sdk.Binary.ModuleWriter.SetMappedMetadataToken(MetadataDeclaration _0, UInt32* _1) 
    at ^R00FfLNj7vE0.^rk33N/hO(OpCodeNumber _0, MetadataDeclaration _1) 
    at ^R00FfLNj7vE0.EmitInstructionMethod(OpCodeNumber _0, IMethod _1) 
    at PostSharp.Sdk.CodeModel.Instruction.Write(BaseInstructionWriter writer, InstructionPrefixes allowedPrefixes) 
    at ^zpGNRK5nUM9z.^x98p/iJs13L+(InstructionReader _0) 
    at PostSharp.Sdk.CodeModel.MethodBodyDeclaration.^uPrQJ6gs(InstructionBlock _0, IMethodBodyVisitor[] _1, MethodBodyVisitLevel _2, InstructionAction _3, InstructionReader _4, InstructionBlockExceptionHandlingKind _5) 
    at ^zpGNRK5nUM9z.^e2BtLyuT(^Kh85h0nXrulm& _0, Int32& _1) 
    at ^zpGNRK5nUM9z.^SkiT(BufferWriter _0) 
    at PostSharp.Sdk.Binary.ModuleWriter.WriteMethodBodies(BufferWriter _0, UInt32 _1) 
    at ^Up6wxUIUnN6a.^VfvrABjR() 
    at ^Up6wxUIUnN6a.^SkiT() 
    at ^cyC/TYSlPGB/.^wvPm(^RtksFin57NJ8 _0, ^8gP93Xsl\+Imn _1) 
    at PostSharp.Sdk.Extensibility.Tasks.CompileTask.Execute() 
    at PostSharp.Sdk.Extensibility.Project.ExecutePhase(String phase) 
    at PostSharp.Sdk.Extensibility.Project.Execute() 
    at PostSharp.Hosting.PostSharpObject.ExecuteProjects() 
    at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation). C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\BusinessLogic_CS_v5.csproj BusinessLogic_CS_v5 

tôi đã đi qua tất cả các tài liệu tham khảo dự án, và không có dự án có sự tham khảo system.web.mvc, version=3.0.0.0. Tất cả các dự án đều tham chiếu 4.0.0.0. Tại sao nó đề cập đến phiên bản 3.0.0.0? Nó có thể tìm thấy nó từ một số GAC hoặc một số cài đặt địa phương?

Nếu tôi tắt PostSharp từ thuộc tính dự án, dự án biên dịch thành công. Vì vậy, nó phải là một cái gì đó liên quan đến PostSharp. Mọi trợ giúp sẽ được đánh giá cao khi tôi bị mất khoảng

+0

Rất có thể là một trong những thư viện bạn đang sử dụng là tham khảo 3.0. Một nơi bạn có thể kiểm tra để biết thêm thông tin là trình xem nhật ký tổng hợp, http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.110).aspx – Phaeze

+0

Trong trường hợp của tôi, hãy thêm NuPet PostSharp trực tiếp được giải quyết vấn đề! (v4.3.3) –

Trả lời

2

Postsharp có thể tham chiếu MVC 3 trong nội bộ. Bạn có thể thử chuyển hướng ràng buộc trong web.config của mình:

<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

Điều này đã có trong web.config/app.config, và vấn đề vẫn còn. –

22

Lỗi này thường được đưa ra khi một số hội đồng bên thứ 3 tham chiếu phiên bản cũ hơn của System.Web.Mvc. Bạn có chuyển hướng ràng buộc trong web.config của bạn, nhưng bạn cũng cần phải nói cho PostSharp sử dụng cấu hình đó trong khi xây dựng. Bạn có thể làm điều đó bằng cách đặt PostSharpHostConfigurationFile tạo thuộc tính cho đường dẫn tệp * .config của bạn.

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

Thực ra việc thêm tệp này vào tệp csproj đã khắc phục được sự cố, nhưng nó thực sự đã giúp! – Dzoukr

+0

có nó đã khắc phục sự cố của tôi nhờ @AlexD –

12

Thêm mã bên dưới vào tệp [project] .csproj của bạn. Để đạt được điều này, hãy thực hiện theo các bước sau:

  • Nhấp chuột phải vào Dự án của bạn;
  • Hủy tải dự án;
  • Sau đó nhấp chuột phải vào dự án chưa được tải và nhấp vào Chỉnh sửa [project] .csproj;
  • Tìm thẻ tag <Import Project của PostSharp;
  • Sau đó, thêm mã sau ngay bên dưới thẻ <Import Project .../>;
  • Sau đó, Tải lại dự án;

Code:

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

mã XML của bạn sẽ giống như:

<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> 
+1

Được thăng hạng vì giả định đúng, rằng không phải ai cũng tự động biết vị trí đặt PropertyGroup. Cảm ơn vì đã tiết kiệm thời gian cho tôi. Làm việc như người ở – MichaelCleverly

Các vấn đề liên quan