Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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:
 
<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:
<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:
<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 22-May-13 4:34am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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>
  Permalink  
Comments
princektd at 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 at 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 at 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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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?
  Permalink  

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

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100