升级.NET Framework 4.5的应用程序 - 无法获取正确的DataAnnotations程序集 [英] Upgrading application for .Net Framework 4.5 - cannot get correct DataAnnotations assembly

查看:243
本文介绍了升级.NET Framework 4.5的应用程序 - 无法获取正确的DataAnnotations程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已升级的应用程序的新构建失败。升级是为.Net Framework 4.0到4.5和EF到版本6.
错误消息是;


Models \ Mapping\vw_EmployeesAndJobTitlesMap.cs(47):无法找到类型名称
'DatabaseGeneratedOption'。此类型已将
转发到程序集System.ComponentModel.DataAnnotations,
Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35。
考虑添加对该程序集的引用。


在日志中我得到以下内容:


建立$ / SCD4 / SCD4.Model / SCD4.Model.csproj.metaproj作为默认
目标。



00:00建立
$ / StandardClassLibrary / StandardClassLibrary / StandardClassLibrary / StandardClassLibrary.csproj
作为默认目标。



00:01建成$ / SCD4 / SCD4.Model / SCD4.Model.csproj作为默认目标。
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets
(847):框架
的引用程序集.NETFramework,Version = v4.5。要解决此问题,请为此框架版本的SDK或Targeting Pack安装
,或者将
应用程序重新定位到安装了SDK
或Targeting Pack的框架版本。请注意,程序集将从全局程序集缓存(GAC)解析
,并将用于代替
引用程序集。因此,您的程序集可能不是正确的
针对您打算的框架。 c:\Builds\1\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib
et45\EntityFramework .dll:引用类型
'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption'
声明它被定义在
'c:\Windows\Microsoft.NET\assembly\ GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll',但找不到c:\Builds\1\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib
et45\EntityFramework.dll:引用类型
'System.ComponentModel.DataAnnotations .Schema.DatabaseGeneratedOption'
声称它在
'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0中定义。 0__31bf3856ad364e35\\ \\ System.ComponentModel.DataAnnotations.dll',但找不到c:\Builds\1\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\packages\ EntityFramework.6.0.2\lib
et45\EntityFramework.dll:引用类型
'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption'
声明它在
中定义'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll',但无法找到c:\Builds\1\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib
et45\EntityFramework .dll:引用类型
'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption'
声明它被定义在
'c:\Windows\Microsoft.NET\assembly\ GAC_MSIL\ System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll',但找不到c:\Builds\1\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib
et45\EntityFramework.dll:引用键入
'System.ComponentModel.DataAnnotations.Schema。 DatabaseGeneratedOption'
声称它在
'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0__31bf3856ad364e35\ System.ComponentModel.DataAnnotations.dll',但找不到
Models\Mapping\vw_EmployeesAndJobTitlesMap.cs(24):找不到类型名称
'DatabaseGeneratedOption'。此类型已将
转发到程序集System.ComponentModel.DataAnnotations,
Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35。
考虑添加对该程序集的引用。


当我点击日志中的链接时,这行似乎是问题;

 使用System.ComponentModel.DataAnnotations.Schema; 

EF是版本6.
错误消息说 c :\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll 不存在,但是当我看起来确实存在。






我的日志文件看起来像;


Build started 20/02/2014 14:38:54。节点1上的项目C:\Builds\2\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\SCD4.sln(默认目标)。
ValidateSolutionConfiguration:构建解决方案配置
调试|任何CPU。项目C:\Builds\2\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\SCD4.sln(1)正在构建
C:\\ \\ Builds\2\SCD4\SCD4 -
Test \Sources\MVC4\SCD4\SCD4\SCD4.csproj.metaproj(2)在节点1上
(默认目标)。项目C:\Builds\2\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\SCD4\SCD4.csproj.metaproj(2)正在构建
C:\Builds\2\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\SCD4.Repository\SCD4.Repository.csproj.metaproj
(3)节点1(默认目标)。项目C:\Builds\2\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\SCD4.Repository\SCD4.Repository.csproj.metaproj
(3)正在构建C:\Builds\2\SCD4\SCD4 -
Test\Sources\StandardClassLibrary\StandardClassLibrary\StandardClassLibrary.csproj
(4)在节点上1(默认目标)。
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(847,9):
警告MSB3644:框架的引用程序集
.NETFramework,Version = v4.5未找到。要解决此问题,请为此框架版本的SDK或Targeting Pack安装
,或者将
应用程序重新定位到安装了SDK
或Targeting Pack的框架版本。请注意,程序集将从全局程序集缓存(GAC)解析
,并将用于代替
引用程序集。因此,您的程序集可能不是正确的
针对您打算的框架。 [C:\Builds\2\SCD4\SCD4 -
Test\Sources\StandardClassLibrary\StandardClassLibrary\StandardClassLibrary.csproj]
PrepareForBuild:创建目录obj\Debug\\ \\。
GenerateTargetFrameworkMonikerAttribute:跳过目标
GenerateTargetFrameworkMonikerAttribute,因为相对于输入文件,所有输出文件都是
最新的。 CoreCompile:

c:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe / noconfig
/ nowarn:1701,1702 / nostdlib + / errorreport:prompt /警告:4
/ define:DEBUG; TRACE / reference:C:\Builds\2\SCD4\SCD4 -
Test\Sources\MVC4\SCD4\packages\\ \\EntityFramework.6.0.2\lib\\\
et40\EntityFramework.dll
/ reference:C:\Builds\2\SCD4\SCD4 -
Test\Sources\\ \\ MVC \\ \\ GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll
/reference:c:\Windows\Microsoft.NET\Framework\v4.0.30319\ mscorlib.dll
/reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4。 \\ \\ System.Configuration.dll
/reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll $ b $ c $ b /reference:C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll
/ reference:C :\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll
/reference:C:\Windows\Microsoft.Net\\ \\assembly\GAC_32\System.Web\v4.0_4.0.0.0 _ _ _ _ _ _ _ _ _ _ _ _ _ _ dll
/reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll
/reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll
/ debug + / debug:full / filealign:512 / optimize-
/out:obj\Debug\StandardClassLibrary.dll / target:library
EmailMessage.cs FileSystem.cs Models\JqueryDataTableParamModel.cs
SessionObjects.cs StandardConstants.cs Dynamic.cs UserMembership.cs
OperationStatus.cs属性\AssemblyInfo.cs RepositoryBase.cs
C:\Users\TFSBuildAgent\AppData\Local\ Temp.NETFramework,Version = v4.5.AssemblyAttributes.cs




< hr>

如何解决这个问题?

解决方案

在.NET Framework 4.5中, EF注释从 EF.dll 移动到 System.ComponentModel.Annotations 程序集。



似乎即使您定位到.NET Framework 4.5,您仍然可以在某个地方引用 EntityFramework.dll v4.4.0.0 p>

因此,您的类将使用4.4.0.0程序集中的属性进行编译。



在运行时,较新的 EntityFramework.dll (5.0.0.0)正在使用,它从 System.ComponentModel.DataAnnotations 程序集中查找属性 - 那些不能因为你有 EF.dll 4.4.0.0,因此看起来像属性被忽略。


My new build for the application I have upgraded fails. The upgrade is for .Net Framework 4.0 to 4.5 and EF to version 6. The error message is;

Models\Mapping\vw_EmployeesAndJobTitlesMap.cs (47): The type name 'DatabaseGeneratedOption' could not be found. This type has been forwarded to assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Consider adding a reference to that assembly.

In the log I get the following;

Built $/SCD4/SCD4.Model/SCD4.Model.csproj.metaproj for default targets.

00:00 Built $/StandardClassLibrary/StandardClassLibrary/StandardClassLibrary/StandardClassLibrary.csproj for default targets.

00:01 Built $/SCD4/SCD4.Model/SCD4.Model.csproj for default targets. c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (847): The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. c:\Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib et45\EntityFramework.dll: Reference to type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims it is defined in 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll', but it could not be found c:\Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib et45\EntityFramework.dll: Reference to type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims it is defined in 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll', but it could not be found c:\Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib et45\EntityFramework.dll: Reference to type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims it is defined in 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll', but it could not be found c:\Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib et45\EntityFramework.dll: Reference to type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims it is defined in 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll', but it could not be found c:\Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib et45\EntityFramework.dll: Reference to type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims it is defined in 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll', but it could not be found Models\Mapping\vw_EmployeesAndJobTitlesMap.cs (24): The type name 'DatabaseGeneratedOption' could not be found. This type has been forwarded to assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Consider adding a reference to that assembly.

When I click on the link in the log, it is this line that seems to be the problem;

using System.ComponentModel.DataAnnotations.Schema;

EF is version 6. The error messages says that c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll does not exist, but when I look it does exist.


My log file looks like;

Build started 20/02/2014 14:38:54. Project "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4.sln" on node 1 (default targets). ValidateSolutionConfiguration: Building solution configuration "Debug|Any CPU". Project "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4.sln" (1) is building "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4\SCD4.csproj.metaproj" (2) on node 1 (default targets). Project "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4\SCD4.csproj.metaproj" (2) is building "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4.Repository\SCD4.Repository.csproj.metaproj" (3) on node 1 (default targets). Project "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4.Repository\SCD4.Repository.csproj.metaproj" (3) is building "C:\Builds\2\SCD4\SCD4 - Test\Sources\StandardClassLibrary\StandardClassLibrary\StandardClassLibrary.csproj" (4) on node 1 (default targets). c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(847,9): warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\Builds\2\SCD4\SCD4 - Test\Sources\StandardClassLibrary\StandardClassLibrary\StandardClassLibrary.csproj] PrepareForBuild: Creating directory "obj\Debug\". GenerateTargetFrameworkMonikerAttribute: Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files. CoreCompile:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib\net40\EntityFramework.dll" /reference:"C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib\net40\EntityFramework.SqlServer.dll" /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll /reference:c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll /reference:"c:\Program Files\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll" /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\StandardClassLibrary.dll /target:library EmailMessage.cs FileSystem.cs Models\JqueryDataTableParamModel.cs SessionObjects.cs StandardConstants.cs Dynamic.cs UserMembership.cs OperationStatus.cs Properties\AssemblyInfo.cs RepositoryBase.cs "C:\Users\TFSBuildAgent\AppData\Local\Temp.NETFramework,Version=v4.5.AssemblyAttributes.cs"


How do I fix this?

解决方案

In .NET Framework 4.5, EF annotations were moved from EF.dll to System.ComponentModel.Annotations assembly.

It seems that even though you target .NET Framework 4.5, you still have a reference to EntityFramework.dll v4.4.0.0 somewhere.

As a result your classes are compiled with attributes from the 4.4.0.0 assembly.

At runtime the newer EntityFramework.dll (5.0.0.0) is being used and it looks for attributes from System.ComponentModel.DataAnnotations assembly - Those cannot be found since you have the ones from EF.dll 4.4.0.0 and therefore it looks like attributes are being ignored.

这篇关于升级.NET Framework 4.5的应用程序 - 无法获取正确的DataAnnotations程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆