Task:
I want to create a project template from a Visual Studio 2012 project, so I can quickly create similar projects. This requires files to be renamed and the root namespace to be changed. Unfortunately, this does not happen...
What has been done:
- I've created the project and replaced certain names as specified by the MSDN pages. One replacement is the
$safeprojectname$
, the other is a custom parameter:$custom1$
. - The project has been exported as a project template via the File --> Export Template... option.
- I've unzipped the created zip file.
- I've edited the .vstemplate and .csproject files. The code is found below.
- I've rezipped the files.
- Visual Studio has been restarted, and a project has been opened.
- I go for Add --> New Project --> *my custom template*, give it a name and add the project.
- The project gets added and
$safeprojectname$
gets replaced. The files are not renamed and$custom1
does not get replaced.
MyTemplate.vstemplate
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>MyTemplateName</Name>
<Description>My Description</Description>
<ProjectType>CSharp</ProjectType>
<ProjectSubType></ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>My Default Name</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="MyTemplate.csproj" File="MyTemplate.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true" TargetFileName="app.config">app.config</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$Data.cs">Data.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$.cs">Main.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$Form.xaml">Form.xaml</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$Form.xaml.cs">Form.xaml.cs</ProjectItem>
<Folder Name="Properties" TargetFolderName="Properties">
<ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Settings.settings">Settings.settings</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Settings.Designer.cs">Settings.Designer.cs</ProjectItem>
</Folder>
</Project>
<CustomParameters>
<CustomParameter Name="$custom1$" Value="Some.Custom.Namespace.Prefix."/>
<CustomParameters>
</TemplateContent>
</VSTemplate>
MyTemplate.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
...
<OutputType>Library</OutputType>
<RootNamespace>$custom1$$safeprojectname$</RootNamespace>
<AssemblyName>$safeprojectname$</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Compile Include="$safeprojectname$.cs" />
<Compile Include="$safeprojectname$Data.cs" />
<Compile Include="$safeprojectname$Form.xaml.cs">
<DependentUpon>$safeprojectname$Form.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Include="$safeprojectname$Form.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>PublicSettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>
Question?
How do I get Visual Studio to change the $custom1$ parameter in the files and to rename the files, like Main.cs, to $safeprojectname$.cs?
What doesn't work
- Following the steps on the MSDN pages got me nowhere; neither the filenames change, nor the custom parameter.
- Searching Google gave me MSDN pages, or references to them.