Grandizer
Grandizer

Reputation: 3025

VS 2012 MultiProject Template will NOT Correctly Reference EF 5

I have 3 Projects in my solution template (Model, DataAccess and Service.) More than one of them need to reference EF 5. When I initially created the first Template Service) the EF.dll was in the references list but had the yellow "can't find it" icon on it. I read that I could put the following XML at the bottom of the .vstemplate file and that took care of that problem:

<WizardExtension>
    <Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
    <FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
</WizardExtension>
<WizardData>
    <packages repository="registry" keyName="AspNetMvc4VS11" isPreunzipped="true">
        <package id="EntityFramework" version="5.0.0" skipAssemblyReferences="true" />
    </packages>
</WizardData>

I then figured out how to create a MultiProject .vstemplate and each of my three SubProjects get created exactly how I want them. However, each of the projects that reference EF 5 are failing to hook up the reference. Each of the sub .vstemplate files has the above XML in it but no luck. I even tried to put that XML in the root .vstemplate with no success. Here is my root .vstemplate:

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup">
    <TemplateData>
        <Name>CCISC WCF Service Template - Empty</Name>
        <Description>This is the multi-project template for creating a WCF Service at the county that contains EF 5 and Elmah.</Description>
        <ProjectType>CSharp</ProjectType>
        <ProjectSubType>
        </ProjectSubType>
        <SortOrder>1000</SortOrder>
        <CreateNewFolder>true</CreateNewFolder>
        <DefaultName>MyService</DefaultName>
        <ProvideDefaultName>true</ProvideDefaultName>
        <LocationField>Enabled</LocationField>
        <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
        <Icon>__TemplateIcon.png</Icon>
    </TemplateData>
    <TemplateContent>
        <ProjectCollection>
            <ProjectTemplateLink ProjectName="Model">Model\Model.vstemplate</ProjectTemplateLink>
            <ProjectTemplateLink ProjectName="DataAccess">DataAccess\DataAccess.vstemplate</ProjectTemplateLink>
            <ProjectTemplateLink ProjectName="Service">Service\Service.vstemplate</ProjectTemplateLink>
        </ProjectCollection>
    </TemplateContent>
</VSTemplate>

And here is just the Service.vstemplate file. No need to give you the rest since they are similar and yet all have the same issue with the reference:

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
    <TemplateData>
        <Name>CCISC Service Template - Empty</Name>
        <Description>This is the Service project for the CCISC WCF Service Template that contains EF 5 and Elmah.</Description>
        <ProjectType>CSharp</ProjectType>
        <ProjectSubType>
        </ProjectSubType>
        <SortOrder>1000</SortOrder>
        <CreateNewFolder>true</CreateNewFolder>
        <DefaultName>CCISC Service Template - Empty</DefaultName>
        <ProvideDefaultName>true</ProvideDefaultName>
        <LocationField>Enabled</LocationField>
        <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
        <Icon>__TemplateIcon.png</Icon>
    </TemplateData>
    <TemplateContent>
        <Project TargetFileName="Service.csproj" File="Service.csproj" ReplaceParameters="true">
            <Folder Name="App_Data" TargetFolderName="App_Data" />
            <Folder Name="App_ReadMe" TargetFolderName="App_ReadMe">
                <ProjectItem ReplaceParameters="true" TargetFileName="County.txt" OpenInEditor="true">County.txt</ProjectItem>
                <ProjectItem ReplaceParameters="true" TargetFileName="Elmah.txt">Elmah.txt</ProjectItem>
            </Folder>
            <ProjectItem ReplaceParameters="true" TargetFileName="IService1.cs">IService1.cs</ProjectItem>
            <ProjectItem ReplaceParameters="true" TargetFileName="packages.config">packages.config</ProjectItem>
            <Folder Name="Properties" TargetFolderName="Properties">
                <ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
            </Folder>
            <ProjectItem ReplaceParameters="false" TargetFileName="Service1.svc">Service1.svc</ProjectItem>
            <ProjectItem ReplaceParameters="true" TargetFileName="Service1.svc.cs">Service1.svc.cs</ProjectItem>
            <ProjectItem ReplaceParameters="true" TargetFileName="Web.config">Web.config</ProjectItem>
            <ProjectItem ReplaceParameters="true" TargetFileName="Web.Debug.config">Web.Debug.config</ProjectItem>
            <ProjectItem ReplaceParameters="true" TargetFileName="Web.Release.config">Web.Release.config</ProjectItem>
        </Project>
    </TemplateContent>
    <WizardExtension>
        <Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
        <FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
    </WizardExtension>
    <WizardData>
        <packages repository="registry" keyName="AspNetMvc4VS11" isPreunzipped="true">
            <package id="EntityFramework" version="5.0.0" skipAssemblyReferences="true" />
        </packages>
    </WizardData>
</VSTemplate>

If it helps, the Path property of the EntityFramework reference is blank.

In the case of the Service project, in the .csproj file, the following XML is in there:

<Reference Include="EntityFramework">
  <HintPath>..\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>

Which I understand would look at the root of the solution for a packages folder and go from there. I suspect the above element was somewhat successful because it does create a Packages folder at the root of the new solution. It just does not seem to update the reference to that.

I even tried to change skipAssemblyReferences to false and that had no change. It seems like I am so close.

Upvotes: 0

Views: 536

Answers (1)

Grandizer
Grandizer

Reputation: 3025

As it turns out, once the projects were saved to the HDD, the "packages" folder was up one level higher. So to take care of this, I changed the following from this:

<Reference Include="EntityFramework">
  <HintPath>..\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>

To this:

<Reference Include="EntityFramework">
  <HintPath>..\..\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>

Note the extra ..\ to go up one more level.

Sadly that did NOT take care of it right away. I had to clear the Visual Studio Template cache. So I had to run the Visual Studio Command Prompt as an Administrator and run the following command:

devenv /installvstemplates

It takes a few minutes but once it was done, everything worked as expected!

Upvotes: 2

Related Questions