我为要设置用户提供的某些属性的VS项目创建了一个模板。所以,我实现IWizard
- 接口:使用IWizard更改项目属性
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;
}
我template's项目文件中现在,我有这样的事情:
<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>
而且在AssemblyInfo.cs
:
[assembly: AssemblyTitle("$assemblyTitle$")]
[assembly: AssemblyCopyright("(C) $copyrightYear$ MyCompany")]
// ...
我能成功地使用向导创建我的项目。它的版权日期从AssemblyInfo.cs
后生成是[assembly: AssemblyCopyright("(C) 8/2016 MyCompany")]
- 这很好。但RootNamespace
的值与projectsname
类似。我已经调试了上面的代码,其中replacementsDictionary
为命名空间提供了正确的条目(请参见下图)。
下面是结果项目
正如你可以看到两个Assembly Name
和Default namespace
含有projectsname
什么,而不是我在用户窗体中输入(值在我的情况下为asdas
)。然而,版权日期可通过Assembly Information
-按钮项目 - >产品 - >应用程序正确设置(图中未显示)。
是不是可以使用replacementDictionary
更改项目属性自己?