Reputation: 37113
I created a template for a VS-project where I want to set some attributes provided by the user. So I implemented IWizard
-interface:
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
string projectPath = replacementsDictionary["$destinationdirectory$"];
string projectName = replacementsDictionary["$projectname$"];
SchemaWizardForm frm = new SchemaWizardForm(projectPath, projectName);
frm.ShowDialog();
this.m_assemblyInfo = frm.AssemblyInfo;
replacementsDictionary["$assemblyTitle$"] = frm.AssemblyInfo.AssemblyName;
replacementsDictionary["$assemblyName$"] = frm.AssemblyInfo.AssemblyName;
replacementsDictionary["$copyrightYear$"] = DateTime.Now.Month + "/" + DateTime.Now.Year;
replacementsDictionary["$defaultNamespace$"] = frm.AssemblyInfo.RootNamespace;
}
Now within my template´s project-file I have something like this:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>$defaultNamespace$</RootNamespace>
<AssemblyName>$assemblyName$</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
</Project>
And in AssemblyInfo.cs
:
[assembly: AssemblyTitle("$assemblyTitle$")]
[assembly: AssemblyCopyright("(C) $copyrightYear$ MyCompany")]
// ...
I can sucessfully create my project using the wizard. Its copyright-date from AssemblyInfo.cs
after generation is [assembly: AssemblyCopyright("(C) 8/2016 MyCompany")]
- which is fine. However the RootNamespace
has a value similar to the projectsname
. I already debugged the above code, where the replacementsDictionary
dontains the correct entry for the namespace (see image below).
Here is the result-project
As you can see both the Assembly Name
and the Default namespace
contain the value from projectsname
instead of what I entered in my user-form (asdas
in my case). However the copyright-date accessable via the Assembly Information
-button at Project-->Propertes-->Application is set correctly (not shown in the image).
Isn´t it possible to change the projects properties themeselfes using a replacementDictionary
?
Upvotes: 0
Views: 324
Reputation: 37113
Obviously we can´t change the project´s properties via such a dictionary. What we can do instead is to modify the projectname
-entry within this map which solved the issue for me. Now Assembly title
, Assembly name
and Default namespace
all refer to that same variable. It is a bit annoying (in particular that we can´t change the name of the assembly and the namespace independently) but this works for me.
replacementsDictionary["$projectname$"] = frm.AssemblyInfo.ProjectName;
replacementsDictionary["$safeprojectname$"] = frm.AssemblyInfo.ProjectName;
Upvotes: 0