I have the following code which adds a project to the current solution from a specified template:
Solution2 solution = GetSolution();
string templatePath = "...";
string genProjectPath = $"C:\\TestVSIX\\{projectName}\\";
try {
solution.AddFromTemplate(templatePath, genProjectPath, projectName);
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine(ex.Message);
}
It seems to work properly to a point, the project is added, the files all seem to be included, but only some of the replacements seem to have happened.
...
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9ED4A85F-9A60-4FEB-9736-7591511FE893}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>$safeprojectname$</RootNamespace>
<AssemblyName>$safeprojectname$</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>true</UseIISExpress>
<Use64BitIISExpress />
...
Where the matching proj file template chunk was defined as:
...
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{$guid1$}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>$safeprojectname$</RootNamespace>
<AssemblyName>$safeprojectname$</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>true</UseIISExpress>
<Use64BitIISExpress />
...
Note that $guid1$ updated while the $safeprojectname$ did not.
Additionally, $safeprojectname$ was not replaced in other files of the project as well.
What I have tried:
I attempted to bind a Wizard class to the template, but it doesn't seem to fire when adding the project using the AddFromTemplate method (research seemes to confirm this).
Additionally, I looked for some mechanism to force the replaces after calling AddFromTemplate, but I did not find any mention of such a thing.
I assume I could manually implement replacements, but before I bother, I'd like to understand why this isn't working properly.