Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet vs Direct Reference of Class w/ EF6 Entities

Tags:

c#

nuget

I have a class library with numerous EF6 entities. I generated a NuGet from this library. Whenever I reference the library directly only the DLL is placed in the bin, however when I install the library via NuGet it copies over the entities *Content.tt and *.tt files into a folder in the project.

I have a couple of questions around this difference:

  1. Why does the NuGet require these files present when a reference to the project does not?

  2. Is there a need for these entity files or am I able to force the NuGet to not clone these files over when installed?

My .nuspec file is standard like follows:

    <?xml version="1.0"?>
    <package >
      <metadata>
        <id>MYID</id>
        <version>12.0.2</version>
        <title>MYTITLE</title>
        <authors>MYNAME</authors>
        <owners></owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description</description>
        <releaseNotes></releaseNotes>
        <copyright>Copyright 2017</copyright>
        <tags></tags>
      </metadata>
    </package>

The commands I am using to generate the package are:

c:\nuget.exe pack MYID.csproj -IncludeReferencedProjects -Prop Platform=AnyCPU

c:\nuget.exe add MYID.1.0.0.nupkg -Source M:\Dev\NuGetPackages

like image 870
Nugs Avatar asked Aug 23 '17 14:08

Nugs


2 Answers

.tt files will not be required unless you are doing runtime code generation. Since you are packaging into a dll, this is a not the case. T4 templates (.tt files) are used by entity framework to generate C# classes from EDMX files, as your objects are changed in the diagram. They will not be required to execute the final code.

Check the answer, How to Exclude a T4 Template from a NuGet Package, you can exclude .tt files from packaging.

like image 192
Amit Kumar Singh Avatar answered Nov 13 '22 00:11

Amit Kumar Singh


A little research over the web shows that this issue occurred to a lot of users between 3.4.3 version to 3.4.4 version and was addressed at version 3.5.0.

As it seems, it was a Microsoft bug between the packages. I do not know which version you are using, but I recommend to check this possibility.

like image 1
Barr J Avatar answered Nov 13 '22 01:11

Barr J