Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 项目项模板:Visual Studio在哪里指定依赖项?_C#_Visual Studio - Fatal编程技术网

C# 项目项模板:Visual Studio在哪里指定依赖项?

C# 项目项模板:Visual Studio在哪里指定依赖项?,c#,visual-studio,C#,Visual Studio,正如这里所解释的,可以自定义项目项模板 但目前我只是想了解它是如何工作的。例如,我解压缩了usercontrol文件,在usercontrol.vstemplate中,我看不到mycontrol.designer.cs如何依赖于mycontrol.cs,因为它在项目文件中显示为: <DependentUpon>mycontrol.cs</DependentUpon> mycontrol.cs 有什么想法吗 更新:是否可以在项目类型模板中的某个位置指定此依赖项?这将比依

正如这里所解释的,可以自定义项目项模板

但目前我只是想了解它是如何工作的。例如,我解压缩了usercontrol文件,在usercontrol.vstemplate中,我看不到mycontrol.designer.cs如何依赖于mycontrol.cs,因为它在项目文件中显示为:

<DependentUpon>mycontrol.cs</DependentUpon>
mycontrol.cs
有什么想法吗

更新:是否可以在项目类型模板中的某个位置指定此依赖项?这将比依赖IDE启发式规则更聪明,IDE启发式规则非常有限,因为它只能识别.Designer.cs而不能识别例如.MyCustom.cs

usercontrol.vstemplate:

<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
  <TemplateData>
    <Name Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="2295" />
    <Description Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="2296" />
    <Icon Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="4532" />
    <TemplateID>Microsoft.CSharp.WindowsFormsUserControl</TemplateID>
    <ProjectType>CSharp</ProjectType>
    <SortOrder>94</SortOrder>
    <RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
    <NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
    <DefaultName>UserControl.cs</DefaultName>
  </TemplateData>
  <TemplateContent>
  <References>
   <Reference>
    <Assembly>System</Assembly>
   </Reference>
   <Reference>
    <Assembly>System.Data</Assembly>
   </Reference>
   <Reference>
    <Assembly>System.Drawing</Assembly>
   </Reference>
   <Reference>
    <Assembly>System.Windows.Forms</Assembly>
   </Reference>
   <Reference>
    <Assembly>System.Xml</Assembly>
   </Reference>
  </References>

    <ProjectItem ReplaceParameters="true" SubType="UserControl">UserControl.cs</ProjectItem>
    <ProjectItem ReplaceParameters="true">UserControl.Designer.cs</ProjectItem>
  </TemplateContent>
</VSTemplate>

Microsoft.CSharp.WindowsFormsUserControl
CSharp
94
2
1.
UserControl.cs
系统
系统数据
系统图
System.Windows.Forms
命名空间
UserControl.cs
UserControl.Designer.cs

IDE足够聪明,可以自己解决这个问题。在一个示例项目中尝试此操作:project+添加新项,类,名为Foo.cs。重复,现在将其命名为Foo.Designer.cs。注意它是如何自动成为Foo.cs的一个子项的。名称中的“.Designer”部分很重要。

对于IDE知道的类型,例如窗口,它会自动计算出来


但是,如果要合并设计器不知道的文件/为文件使用不同的命名模式,则必须手动添加标记。我曾在一个项目中尝试过这一点,我认为这是不值得的,还因为IDE只会自动重命名它知道的依赖文件(当您更改主文件的文件名时)。

目前手动添加标记这就是我正在做的:(是的,我似乎也很感兴趣。但我经常重命名文件(我每个文件有一个类,名称保持不变)。每次重构类名时,我都必须卸载项目,更改引用,然后加载项目。仅仅为了得到一个更漂亮的文件树,这很快就变得太多了。如果我想要.mycustom.cs呢?如果我只能依赖IDE,我就陷入了困境。有没有办法用项目类型模板或其他任何东西来指定?目前为止我还没有找到,但是它可能是那些未记录的特性之一