Visual Studio 2012 - Can't move EF .tt files

前端 未结 3 1675
时光说笑
时光说笑 2021-02-02 16:35

I noticed in VS2012 that when you make a new EF Model (.edmx) that the DbContext is the default code generation and the .tt (T4 template) files are now nested underneath

相关标签:
3条回答
  • 2021-02-02 16:38

    It is some strange new feature where templates are added as dependency to EDMX file. You can fix it by editing .csproj file for your project (you can do it in notepad or unload project in VS and edit it). You will find something like this:

    <None Include="Model.tt">
      <Generator>TextTemplatingFileGenerator</Generator>
      <DependentUpon>Model.edmx</DependentUpon>
      <LastGenOutput>Model.cs</LastGenOutput>
    </None>
    

    You just need to remove DependentUpon element and the template item will become independent part of the project.

    0 讨论(0)
  • 2021-02-02 16:49

    I'm using EF5.x a DBContext in a separate project to the EF data model. Despite removing the DependentUpon entry in the project file as stated by Ladislav and here the classes were still appearing under my Model1.tt file.

    To get round this, I had to also remove part of the entries from the project file for each of the tables:

    <Compile Include="MyTableName.cs">
      <DependentUpon>Model1.tt</DependentUpon>
    </Compile>
    

    Only lines with the <DependentUpon> tags should be removed whilst the <Compile Include="..."> tags should be kept. Removing the whole entry will cause the file to disappear from the project list. The entries can be shortened to <Compile Include="MyTableName.cs"\> for brevity.

    0 讨论(0)
  • 2021-02-02 16:53

    Instead of editing project files, I add a EF model of the same name to the project, close the solution, copied the model files from the other project, and reopen the solution. I change the namespace in the edmx properties and then recompile the model.

    0 讨论(0)
提交回复
热议问题