我正在构建多项目模板。 其中一个子项目是ASP.NET Web应用程序。 当我将它作为单个项目模板导出时,一切都很好,但是当包含在多项目模板中时,几乎一半的引用都被破坏了(Antlr3.Runtime,EntitiFramework,Microsoft.Owin等等)
多项目模板如下所示:
<VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"> <TemplateData> <Name>Web Api Solution Template</Name> <Description>Template commonly used in projects</Description> <ProjectType>CSharp</ProjectType> <ProjectSubType> </ProjectSubType> <SortOrder>1000</SortOrder> <CreateNewFolder>true</CreateNewFolder> <DefaultName>Web_API</DefaultName> <ProvideDefaultName>true</ProvideDefaultName> <LocationField>Enabled</LocationField> <EnableLocationBrowseButton>true</EnableLocationBrowseButton> <Icon>IconSolution.png</Icon> </TemplateData> <TemplateContent> <ProjectCollection> <ProjectTemplateLink ProjectName="Api"> Api\MyTemplate.vstemplate </ProjectTemplateLink> <ProjectTemplateLink ProjectName="BLL"> BLL\MyTemplate.vstemplate </ProjectTemplateLink> <ProjectTemplateLink ProjectName="DBModel"> DBModel\MyTemplate.vstemplate </ProjectTemplateLink> <ProjectTemplateLink CopyParameters="true" ProjectName="Web"> Web\MyTemplate.vstemplate </ProjectTemplateLink> </ProjectCollection> </TemplateContent> </VSTemplate>为什么会那样?
I am building multi project template. One of the child projects is ASP.NET web application. When I export it as a single project template then everything is fine, but when included in multi project template, almost half of references are broken (Antlr3.Runtime, EntitiFramework, Microsoft.Owin and many others)
Multi project template looks like this:
<VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"> <TemplateData> <Name>Web Api Solution Template</Name> <Description>Template commonly used in projects</Description> <ProjectType>CSharp</ProjectType> <ProjectSubType> </ProjectSubType> <SortOrder>1000</SortOrder> <CreateNewFolder>true</CreateNewFolder> <DefaultName>Web_API</DefaultName> <ProvideDefaultName>true</ProvideDefaultName> <LocationField>Enabled</LocationField> <EnableLocationBrowseButton>true</EnableLocationBrowseButton> <Icon>IconSolution.png</Icon> </TemplateData> <TemplateContent> <ProjectCollection> <ProjectTemplateLink ProjectName="Api"> Api\MyTemplate.vstemplate </ProjectTemplateLink> <ProjectTemplateLink ProjectName="BLL"> BLL\MyTemplate.vstemplate </ProjectTemplateLink> <ProjectTemplateLink ProjectName="DBModel"> DBModel\MyTemplate.vstemplate </ProjectTemplateLink> <ProjectTemplateLink CopyParameters="true" ProjectName="Web"> Web\MyTemplate.vstemplate </ProjectTemplateLink> </ProjectCollection> </TemplateContent> </VSTemplate>Why is it like that?
最满意答案
通过使用模板向导扩展解决了它。 基本上我做的是从子项目中删除所有预先安装的nuget包,并使用向导扩展添加它们,以便project.vstemplate的结尾如下所示:(在这种情况下为api)
<WizardExtension> <Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly> <FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName> </WizardExtension> <WizardData> <packages> <package id="EntityFramework" version="6.1.1" targetFramework="net45" /> <package id="Microsoft.AspNet.Identity.Core" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Identity.EntityFramework" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Identity.Owin" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Cors" version="5.2.3" /> <package id="Microsoft.AspNet.Mvc" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Razor" version="3.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Client" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Core" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebPages" version="3.2.0" targetFramework="net45" /> <package id="Owin" version="1.0" targetFramework="net45" /> <package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" /> <package id="Microsoft.Owin.Cors" version="3.0.1" targetFramework="net45" /> <package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Cookies" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Facebook" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Google" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.OAuth" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Twitter" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" /> <package id="Newtonsoft.Json" version="6.0.3" targetFramework="net45" /> </packages> </WizardData> </VSTemplate>据我记忆,你可以复制粘贴装配部件,因为它将来不会改变。
Solved it by using template wizard extension. Basically what I did, was remove all the preinstalled nuget packages from child projects and add them with wizard extension so that the end of project.vstemplate looks like this: (api in this case)
<WizardExtension> <Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly> <FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName> </WizardExtension> <WizardData> <packages> <package id="EntityFramework" version="6.1.1" targetFramework="net45" /> <package id="Microsoft.AspNet.Identity.Core" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Identity.EntityFramework" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Identity.Owin" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Cors" version="5.2.3" /> <package id="Microsoft.AspNet.Mvc" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Razor" version="3.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Client" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Core" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.0" targetFramework="net45" /> <package id="Microsoft.AspNet.WebPages" version="3.2.0" targetFramework="net45" /> <package id="Owin" version="1.0" targetFramework="net45" /> <package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" /> <package id="Microsoft.Owin.Cors" version="3.0.1" targetFramework="net45" /> <package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Cookies" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Facebook" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Google" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.OAuth" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Twitter" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" /> <package id="Newtonsoft.Json" version="6.0.3" targetFramework="net45" /> </packages> </WizardData> </VSTemplate>As far as I remember, you can copy paste the Assembly part as it won't change in the future.
更多推荐
发布评论