44

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:

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`

How can I fix this ?

What am I missing ?

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
Gil
  • 1,113
  • 2
  • 12
  • 13
  • You should consider using a code first approach, rather than the designer, even if you want the code to generate your model for you. – Yuck May 17 '13 at 13:52
  • 1
    Doing it using CodeFirst is not the issue here. This is just a sample test project to do a little testing with EF5 but unfortunately this error occurred. Can anyone help me ? – Gil May 17 '13 at 14:07
  • see [purpose of EF 6.x DbContext Generator](http://stackoverflow.com/a/23037604) – Michael Freidgeim Jul 11 '16 at 05:19

4 Answers4

52

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).

eternity
  • 1,668
  • 15
  • 25
  • 7
    FYI, noobs like me, POCO="Plain Old CLR Object" – BlueMonkMN Nov 20 '13 at 16:01
  • 1
    For me, it was Add > New Item... > EF 5.x DbContext Generator. I had selected this, but then decided I didn't want it, tried deleting "Model1.Context.tt" and "Model1.tt", then got this error. If you go back in and readd it like suggested, then clear or update the "const string inputFile" line in Model1.tt, you can get rid of the error, but what do you put? And what if you just want to get rid of the EF Generator without starting over? I'd say this is a weak answer. – vapcguy Sep 17 '14 at 02:10
47

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

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.

Alex
  • 14,104
  • 11
  • 54
  • 77
12

In my case I was inadvertently adding the EF Db Context Generator instead of Entity Framework. Total PEBKAC but I'm posting it here as I'm sure I will not be the only one.

I noticed that the file extension was TT as this is a text template not the EDMX that I wanted.

If you are looking to add entity then add ADO.NET Entity Data Model not EF X.x DbContext Generator

workabyte
  • 3,496
  • 2
  • 27
  • 35
2

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.

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.

Next, I did some poking around and I found out that my project's ".csproj" file was modified with this:

<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.

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.

vapcguy
  • 7,097
  • 1
  • 56
  • 52
  • For those that actually WANT the EF 5.x DbContext Generator, I found in Googling that you would put in the .edmx file name into the string, I'm assuming "Model1.edmx", in my case, but since I did not see an .edmx file anywhere, I actually don't know for sure. – vapcguy Sep 17 '14 at 02:33