Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
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:

C#
<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>


Here is the code in the template's .vstemplate file:
C#
<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>


here is some code from the template's .csproj:
C#
<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?
Posted

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?

XML
<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>
 
Share this answer
 
Comments
princektd 23-May-13 0:54am    
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?
code_madi 23-May-13 1:48am    
What is the objective behind including this dll? I think both approaches could work. It just depends on whether you want the dll to be totally integrated with the template (thus making it self-sufficient in a way)
princektd 25-May-13 1:30am    
I want to make the template self sufficient. The point is, the dll i am including is something i made. So of course other systems wont have it. So, it would be nice to get it included in the template itself.

By the way, I tried your suggestion. But, some of the files were already mentioned with the proper path and some were not. I corrected these, and now everything works. Except the DLL. These too i mentioned the proper path and everything, but after building and installing the template, when i create the new proj, these show up with an exclamation mark...

Another wierd thing is, you know, when u add a new windows form, you can see the Form.cs in your solution explorer with a tiny triangle to its left. Click on the triangle and it expands to show Form.Designer.cs and If resources are present then Form.resx under your Form.cs, as if they were on the 'next level' in your solution tree... I know actually the files ie, .cs, designer and resx are all in the same folder, but somehow linked so that solution explorer shows them that way... Well, I say the designer and resx files work now, but still, they dont show up 'UNDER' the form.cs. Rather these are displayed on the SAME LEVEL as form.cs, but they work. I checked by adding a button to Form.cs and the desiger.cs automatically reflect it as well as the resx too. But why wont these be displayed as being 'under' as is normaly the case? Of course, even when using my template, only the already present form and settings have this problem. if i add a new form or settings or resource files, their linked files are properly displayed... Any ideas?
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?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900