Visual Studio自定义模板 [英] Visual Studio Custom Template

查看:130
本文介绍了Visual Studio自定义模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在尝试制作一个自定义的项目模板。

我已经添加了文件夹和类文件以及它正确编译。我建立了模板,我可以将其安装到VS2012中,然后通过选择此模板创建一个新项目,它工作正常。

问题发生在Windows窗体和设置文件中模板。



如你所知,windows form.cs还有一个链接到它的form.Designer.cs文件,以及一个.resx文件。 br />
我已经包含了designer.cs和.resx文件,但正如我所说,当我使用模板创建一个新项目时,form.cs和form.Designer.cs文件存在,但他们没有联系。如果我在表单中添加一个新按钮,我看不到对form.Designer.cs的任何更改,而是设计器生成的代码现在似乎是在form.cs本身中生成的。



同样的问题发生在设置文件中。



这是项目'.csproj文件中的代码:



Ok, I am trying to make a custom Project template.
I have added the folders and class files and things and it compiles properly. I get the template built and I can install it into VS2012, then create a new project by selecting this template and it works fine.
The problem happens in the Windows Form and the settings file which are present in the template.

As you know, a windows form.cs also has a form.Designer.cs file linked to it, as well as a .resx file.
I have included the designer.cs and the .resx file, but as i said, when i use the template to create a new project, the form.cs and the form.Designer.cs files are present, but they are not linked. If I add a new button to the form, I see no changes to the form.Designer.cs, instead the designer generated code now seems to be generated in the form.cs itself.

The same problem happens to the settings file.

Here is the code in the project''s .csproj file:

<ItemGroup>
    <Compile Include="App.config" />
    <Compile Include="Program.cs" />
    <Compile Include="Bussiness_Logic_Layer\Sample_Logic.cs" />
    <Compile Include="Bussiness_Logic_Layer\Interfaces\Sample_Interface.cs" />
    <Compile Include="Bussiness_Objects_Layer\Sample_Object.cs" />
    <Compile Include="Data_Access_Layer\Sample_Data_Access.cs" />
    <Compile Include="User_Interface_Layer\Sample_User_Interface.cs" />
		<Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Properties\Settings.settings" />
    <Compile Include="Resources\Sample_Resource.resx" />
</ItemGroup>





这是模板'.vstemplate文件中的代码:



Here is the code in the template''s .vstemplate file:

<TemplateContent>
    <Project File="ProjectTemplate.csproj" ReplaceParameters="true">
      <ProjectItem ReplaceParameters="true" TargetFileName="Properties\AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="true">App.config</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="true">Program.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="false">Bussiness_Logic_Layer\Sample_Logic.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="false">Bussiness_Logic_Layer\Interfaces\Sample_Interface.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="false">Bussiness_Objects_Layer\Sample_Object.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="false">Data_Access_Layer\Sample_Data_Access.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="true">User_Interface_Layer\Sample_User_Interface.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="false">User_Interface_Layer\Sample_User_Interface.Designer.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="false">User_Interface_Layer\Sample_User_Interface.resx</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="false">Properties\Settings.settings</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="false">Properties\Settings.Designer.cs</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="false">Resources\Sample_Resource.resx</ProjectItem>
      <ProjectItem ReplaceParameters="true" OpenInEditor="false">Resources\Sample_Resource.Designer.cs</ProjectItem>
    </Project>
  </TemplateContent>





这里是模板'.csproj的一些代码:



here is some code from the template''s .csproj:

<ItemGroup>
    <Compile Include="Bussiness_Logic_Layer\Interfaces\Sample_Interface.cs" />
    <Compile Include="Bussiness_Logic_Layer\Sample_Logic.cs" />
    <Compile Include="Bussiness_Objects_Layer\Sample_Object.cs" />
    <Compile Include="Data_Access_Layer\Sample_Data_Access.cs" />
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
      <DependentUpon>Settings.settings</DependentUpon>
    </Compile>
    <Compile Include="Resources\Sample_Resource.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Sample_Resource.resx</DependentUpon>
    </Compile>
    <Compile Include="User_Interface_Layer\Sample_User_Interface.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="User_Interface_Layer\Sample_User_Interface.Designer.cs">
      <DependentUpon>Sample_User_Interface.cs</DependentUpon>
    </Compile>
  </ItemGroup>





我的问题是,如何正确包含模板中的设置或窗体,以便其关联的设计器和资源文件保持正确链接?



My question is, how to properly include a settings or a windows form in a template so that its associated designer and resource files remain properly linked?

推荐答案

C onfig看起来很不错但是......

指的是模板的.csproj代码。可能是DependentUpon字段可以更具体,也可以使用项目文件夹名称吗?



Config looks good but...
referring to the template''s .csproj code. Could it be that the DependentUpon field can be more specific i.e. use the project folder name in it as well?

<ItemGroup>
    <Compile Include="Bussiness_Logic_Layer\Interfaces\Sample_Interface.cs" />
    <Compile Include="Bussiness_Logic_Layer\Sample_Logic.cs" />
    <Compile Include="Bussiness_Objects_Layer\Sample_Object.cs" />
    <Compile Include="Data_Access_Layer\Sample_Data_Access.cs" />
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
      <DependentUpon>Settings.settings</DependentUpon>
    </Compile>
    <Compile Include="Resources\Sample_Resource.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Sample_Resource.resx</DependentUpon>
    </Compile>
    <Compile Include="User_Interface_Layer\Sample_User_Interface.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="User_Interface_Layer\Sample_User_Interface.Designer.cs">
      <DependentUpon>User_Interface_Layer\Sample_User_Interface.cs</DependentUpon>
    </Compile>
  </ItemGroup>


aah ...这似乎是一个好主意。我会看到它。

非常感谢。



另外说,我想在LIB文件夹中有一个dll模板。然后在参考部分,我应该提到文件夹路径还是只是dll名称,并在文件中包含Lib文件夹和dll作为文件?
aah... that seems a good idea. I''ll see to it.
Thanks a lot.

Also say, i want to have a dll in LIB folder in the template. Then in the reference section, should I mention the folder path or just the dll name and include the Lib folder and dll as files in the template?


这篇关于Visual Studio自定义模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆