c# - .Net Framework 4.5 的升级应用程序 - 无法获得正确的 DataAnnotations 程序集

标签 c# entity-framework

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

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.



在日志中,我得到以下信息;

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.



当我点击日志中的链接时,这行似乎是问题所在;
using 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. 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"



我该如何解决?

最佳答案

您可以通过添加对它提到的 DLL 的引用来解决此问题。

在 Visual Studio (2010/2012/2013) 中,右键单击项目的引用并选择“添加引用”。

然后选择 Assemblies 选项卡并导航到 System.ComponentModel.DataAnnotations 并勾选复选框。然后选择“确定”,将添加引用。

只要您还有 using System.ComponentModel.DataAnnotations;,您的项目现在应该可以正确构建。在你的.cs 文件中。

关于c# - .Net Framework 4.5 的升级应用程序 - 无法获得正确的 DataAnnotations 程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21834070/

相关文章:

c# - 将依赖项注入(inject)动态加载的 .dll (.net core)

entity-framework - 首先设置 "Default value or binding" Entity Framework 代码

entity-framework - Entity Framework : cross join causes OutOfMemoryException

c# - 如何将自定义函数转换为 Entity Framework Core 3.1 的 sql 表达式

c# - Await Task.WhenAll() 内部任务不等待

c# - SharePoint 子网站 - 遍历列表

c# - Go to Href <a href =""> From .Cs 文件函数

c# - Bot 框架 - Microsoft.Rest.ClientRuntime 元数据错误

c# - Entity Framework 在工作量大的情况下抛出意外异常

c# - EntityFramework - 包含复合键的查询