I have successfully created a multiproject template using this guide: https://github.com/ligershark/side-waffle/wiki/How-to-create-a-multi-project-template
The issue im having is the ability to change the default namespace and default assembly name for the generated projects. Like it is explained here: http://reasoncodeexample.com/2013/06/09/creating-visual-studio-project-templates/ where a custom parameter defines f.ex. the default namespace.
Essentially i would like to ensure that our company name is always in the beginning of the namespace...
I cannot make it work with the SideWaffle project template, and im wondering if anyone has an idea as to how one can define the default namespace and assemblyname, while using the SideWaffle project template.
I have tracked down what goes on. Since it will be a lengthy post i will make a new answer that explains the problems @ThBlitz
This is not an answer, but a further explanation into the above issues, and i apologize for the length.
So i have setup a IWizard implementation to modify the csproj and as discussed with @Sayed i have tried his solution. Here are my findings.
This is the interresting part of the IWizard
implementation
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
replacementsDictionary.Add("$companynamespace$", "Infomedia");
}
And the _preprocess.xml
<?xml version="1.0" encoding="utf-8" ?>
<Preprocess>
<TemplateInfo Path="CSharp\Infomedia"/>
<Replacements Include="*.*" Exclude="*.vstemplate;*.csproj;*.jpg;*.png;*.ico;_preprocess.xml;_project.vstemplate.xml">
<add key="ConsoleApp" value="$safeprojectname$"/>
<add key="RootNamespace" value="$companynamespace$.$safeprojectname$"/>
<add key="AssemblyName" value="$companynamespace$.$safeprojectname$"/>
<add key="namespace" value="namespace $companynamespace$.$safeprojectname$"/>
</Replacements>
</Preprocess>
The namespace part is only to test that the wizard is executed, and indeed it is, because i can observe that change to namespacing in all classes in the template in the experimental VS. (the classes are then invalid, but at least it shows the execution of the wizard).
But it should change the RootNamespace
and Assemblyname
and to do that i will need to remove the exclusion of *.csproj
in the _preprocess.xml
Doing this change invalidates the xml.
Example of cleaned _preprocess.xml
<?xml version="1.0" encoding="utf-8" ?>
<Preprocess>
<TemplateInfo Path="CSharp\Infomedia"/>
<Replacements Include="*.*" Exclude="*.vstemplate;*.jpg;*.png;*.ico;_preprocess.xml;_project.vstemplate.xml">
<add key="ConsoleApp" value="$safeprojectname$"/>
<add key="RootNamespace" value="$companynamespace$.$safeprojectname$"/>
<add key="AssemblyName" value="$companynamespace$.$safeprojectname$"/>
<add key="namespace" value="namespace $companynamespace$.$safeprojectname$"/>
</Replacements>
</Preprocess>
observe the removal of *.csproj
Building the solution will cause compile error:
Name cannot begin with the '$' character, hexadecimal value 0x24. Line 10, position 6.
Ok. so the problem is now the presense of $
and removing them and any whitespaces will allow the solution to build, but of course the replacement will not work, since the replacement values cannot be found.
Modified xml that builds but does not work.
<?xml version="1.0" encoding="utf-8" ?>
<Preprocess>
<TemplateInfo Path="CSharp\Infomedia"/>
<Replacements Include="*.*" Exclude="*.vstemplate;*.jpg;*.png;*.ico;_preprocess.xml;_project.vstemplate.xml">
<add key="ConsoleApp" value="$safeprojectname$"/>
<add key="RootNamespace" value="companynamespace.safeprojectname"/>
<add key="AssemblyName" value="companynamespace.safeprojectname"/>
<add key="namespace" value="companynamespace.safeprojectname"/>
</Replacements>
</Preprocess>
So @Sayed i really hope you have an idea as to what is going on here.