Nuget不会将Entity Framework安装到C ++ / CLI项目中 [英] Nuget won't install Entity Framework into C++/CLI project

查看:354
本文介绍了Nuget不会将Entity Framework安装到C ++ / CLI项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这个问题已修复。我使用Visual Studio 2013,它是Entity Framework 6.1。我收到错误消息:PublicKeyToken = xxxxxx未标记为可序列化。

I thought this problem was fixed. I'm using Visual Studio 2013 and it is Entity Framework 6.1. I get the error message: PublicKeyToken=xxxxxx is not marked as serializable.

我认为这是修复。如果是,是否有解决方法?

I thought this was fixed. Is it broken again and if so, is there a workaround?

谢谢。

尝试安装到win32 C ++控制台应用程序时的消息。 (使用默认设置构建,没有其他添加到新构建。)
错误:类型
'Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCProjectShim'在程序集
'Microsoft.VisualStudio.Project .VisualC.VCProjectEngine,Version = 12.0.0.0,Culture = neutral,
PublicKeyToken = b03f5f7f11d50a3a'未标记为可序列化。

Here is the complete error message when trying to install into a win32 C++ console application. (Built with default settings, no other adds to new build.) Error: Type 'Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCProjectShim' in Assembly 'Microsoft.VisualStudio.Project.VisualC.VCProjectEngine, Version=12.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.

这是完整的错误消息当尝试安装到C ++ CLR:
(实际上,它是完全相同的错误消息。)

Here is the complete error message when trying to install into a C++ CLR: (Actually, it's the exact same error message.)

这是完整的错误消息,一个空的C ++项目:
(同样的错误信息。)

Here is the complete error message when trying to install into a General Empty C++ Project: (Again, same error message.)

推荐答案

你在做什么。您正在尝试运行Nuget下载并将Entity Framework安装到C ++项目中。是的,这将是一个失败的鲸鱼。 Nuget获得了在2.5版本安装C ++库的能力,但只适用于 native 库。纯C ++,不是像EF这样的托管代码。作为一个相对较新的功能,它不会阻止你弄错它,它不会过滤可用的包到C ++项目中可以工作的类。

Okay, I can finally figure out what you are doing. You are trying to run Nuget to download and install the Entity Framework into a C++ project. Yes, that's going to be a fail-whale. Nuget acquired the ability to install C++ libraries at version 2.5, but that only works for native libraries. Pure C++, not managed code like EF. Being a relatively new feature, it doesn't do anything to stop you from getting it wrong, it doesn't filter the available packages to the kind that can work in a C++ project.

失败的步骤是最后一步,下载和复制文件工作正常,但Nuget运行Powerscript脚本来修改项目属性。其中,对于EF,写在C#或VB.NET项目中工作。用于C ++项目的VS扩展模型(由错误消息中报告的VCProjectEngine类实现)太不同,无法成功完成该脚本。

The step that fails is the final one, download and copying files work okay but then Nuget runs a Powerscript script to modify the project properties. Which, for EF, was written to work in a C# or VB.NET project. The VS extension model for C++ projects (implemented by the VCProjectEngine class as reported in the error message) is too different to permit that script to complete successfully.

请记住在本地C ++项目中使用EF的几率为零。你只会在C ++ / CLI项目中有一个很小的镜头。从一个项目模板开始在CLR节点是一个必要的第一步。

Do keep in mind that the odds of using EF in a native C++ projects are zero. You'll only have a smallish shot at it in a C++/CLI project. Starting with a project template in the CLR node is a required first step.

下一个是愚弄Nuget安装程序,添加一个虚拟C#项目到您的解决方案,并运行Nuget将EF安装到该项目中。你会看到它添加一个app.config文件到项目,你需要在你的C ++ / CLI项目中做同样的。它添加了两个EF组件,您还需要添加到您的C ++ / CLI项目:

The next one is to fool the Nuget installer, add a dummy C# project to your solution and run Nuget to get EF installed into that project. You'll see it adding an app.config file to the project, you need to do the same in your C++/CLI project. And it adds two EF assemblies that you also need to add to your C++/CLI project:


  • 右键单击解决方案资源管理器

  • 选择常用属性+参考
  • 单击添加新参考按钮


  • 导航到虚拟C#项目的 packages\EntityFramework.6.1.0\lib\\\
    et45

  • 选择您在其中看到的EntityFramework.dll

  • 重复此步骤,在其中添加EntityFramework.SqlServer.dll。

  • Right-click the project in the Solution Explorer window, Properties
  • Select Common Properties + References
  • Click the Add New Reference button
  • Click the Browse button
  • Navigate to the dummy C# project's packages\EntityFramework.6.1.0\lib\net45 directory
  • Select EntityFramework.dll you see there
  • Repeat to add EntityFramework.SqlServer.dll there.

一定要编写C ++ / CLI代码来使用它。当心你会有一个爱斯基摩的机会找到任何。更好的方法是创建一个使用EF并在C ++ / CLI项目中使用该库的C#库。

Be sure to write C++/CLI code to use it. Beware that you'll have a Eskimo's chance to find any. The much saner approach is to create a C# library that uses EF and use that library in a C++/CLI project.

这篇关于Nuget不会将Entity Framework安装到C ++ / CLI项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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