C# EF5 启动项目:运行转换时出错:请覆盖替换标记“$edmxInputFile$”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16610602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
EF5 Starting a Project:Error Running transformation: Please overwrite the replacement token '$edmxInputFile$'
提问by Gil
I'm creating a Console Project in VS2012 with .Net4.5. After it I "Add", "New Item" to the project, and choose "EF 5.x DbContext Generator". Then, after a couple of seconds the following error message appears in the 'Error List' tab:
我正在使用 .Net4.5 在 VS2012 中创建一个控制台项目。之后我“添加”,“新项目”到项目,然后选择“EF 5.x DbContext Generator”。然后,几秒钟后,“错误列表”选项卡中会出现以下错误消息:
Error 1 Running transformation: Please overwrite the replacement token '$edmxInputFile$' with the actual name of the .edmx file you would like to generate from. C:\Projects\Tests\ConsoleAppEF5\ConsoleAppEF5\Model1.tt`
错误 1 运行转换:请使用您要从中生成的 .edmx 文件的实际名称覆盖替换标记“$edmxInputFile$”。C:\Projects\Tests\ConsoleAppEF5\ConsoleAppEF5\Model1.tt`
How can I fix this ?
我怎样才能解决这个问题 ?
What am I missing ?
我错过了什么?
回答by eternity
You should create edmx model first to generate POCO's from it automatically. You can add it through menu (Add New Item -> ADO.NET Entity Data Model). After the model will be created you can use the DbContext generator. Replace $edmxInputFile$ with the name of your edmx file and then save file you are edit (though VS 2012 should do it automatically).
您应该首先创建 edmx 模型以自动从中生成 POCO。您可以通过菜单(添加新项 -> ADO.NET 实体数据模型)添加它。创建模型后,您可以使用 DbContext 生成器。将 $edmxInputFile$ 替换为您的 edmx 文件的名称,然后保存您正在编辑的文件(尽管 VS 2012 应该自动执行此操作)。
回答by vapcguy
In my case, I decided I wanted to get rid of the EF 5.x DbContext Generator. I got this error when I selected to add it, but then deleted "Model1.Context.tt" and "Model1.tt" after thinking better of it. Unfortunately for me, I didn't realize that's not all I had to do. When I did another "Build", I got the OP's error.
就我而言,我决定要摆脱 EF 5.x DbContext Generator。当我选择添加它时,我收到了这个错误,但在考虑好之后删除了“Model1.Context.tt”和“Model1.tt”。对我来说不幸的是,我没有意识到这不是我要做的全部。当我进行另一个“构建”时,出现了 OP 的错误。
My next steps: I went to Model1.tt, cleared out $edmxInputFile$and left it as an empty string and clicked to build the project. This gave me an UnauthorizedException error (which is fine, I didn't want it modifying anything, anyway). I just wanted it to get rid of the original error.
我的后续步骤:我转到 Model1.tt,清除$edmxInputFile$并将其保留为空字符串,然后单击以构建项目。这给了我一个 UnauthorizedException 错误(这很好,无论如何我不想它修改任何东西)。我只是想让它摆脱原来的错误。
Next, I did some poking around and I found out that my project's ".csproj" file was modified with this:
接下来,我进行了一些探索,我发现我的项目的“.csproj”文件被修改为:
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
Now I don't think this GUID is going to be the same in all cases of the error, or even everytime anyone adds on the EF 5.x DbContext Generator. But if your .csproj file (NOTE: this is different than your .csproj.user file) has been changed (hopefully it's in source control and you can tell this), you should be able to figure out how. I deleted this section, did a "Build", and got rid of my errors.
现在我认为这个 GUID 不会在所有错误情况下都相同,甚至每次有人添加到 EF 5.x DbContext Generator 时也是如此。但是,如果您的 .csproj 文件(注意:这与您的 .csproj.user 文件不同)已更改(希望它在源代码管理中并且您可以告诉这一点),您应该能够弄清楚如何。我删除了这一部分,做了一个“构建”,并摆脱了我的错误。
If it's not in source control, you can always create a dummy project and compare your .csproj file to that project's file, and do some trial and error by taking out anything that is extra on your .csproj and doing a "Build" (saving things to Notepad, putting them back if it doesn't clear your error). I know this is a helluva way to do it, but at least you won't waste time redoing your entire solution.
如果它不在源代码管理中,您始终可以创建一个虚拟项目并将您的 .csproj 文件与该项目的文件进行比较,然后通过取出 .csproj 上的任何额外内容并进行“构建”(保存记事本,如果它不能清除您的错误,请将它们放回原处)。我知道这是一种极好的方法,但至少您不会浪费时间重做整个解决方案。
回答by Alex
And in another scenario, this is apparently a known bug: http://web.archive.org/web/20131203074519/http://connect.microsoft.com/VisualStudio/feedback/details/498723/ado-net-entityobject-generator-error-list-bug
在另一种情况下,这显然是一个已知错误:http://web.archive.org/web/20131203074519/http: //connect.microsoft.com/VisualStudio/feedback/details/498723/ado-net-entityobject-生成器错误列表错误
So if you add a DbContext Generator and then remove it and you get this error, just close and reopen the project. Solved it for me.
因此,如果您添加一个 DbContext 生成器,然后将其删除并出现此错误,只需关闭并重新打开项目即可。为我解决了。
回答by workabyte
In my case I was inadvertently adding the EF Db Context Generatorinstead of Entity Framework. Total PEBKACbut I'm posting it here as I'm sure I will not be the only one.
在我的情况下,我无意中添加了EF Db Context Generator而不是Entity Framework. 总计,PEBKAC但我将其发布在这里,因为我确信我不会是唯一的。
I noticed that the file extension was TTas this is a text template not the EDMXthat I wanted.
我注意到文件扩展名是TT因为这是一个文本模板,而不是EDMX我想要的。
If you are looking to add entity then add ADO.NET Entity Data ModelnotEF X.x DbContext Generator
如果你希望增加实体然后加入ADO.NET Entity Data Model不EF X.x DbContext Generator

