Visual Studio 里怎么把partial class的2个文件做成从属关系

来源:本网整理
Visual Studio 里如何把partial class的2个文件做成从属关系
就像新建一个winForm,Form1.Designer.cs会挂在Form1.cs的下面一样。我想自己建2个文件也达到这个效果。
我用codesmith自动产生的代码会有这个效果,但是把2个文件复制到新的项目里,再引进项目后就变成2个独立的文件了。
实在是想不明白 这个隶属关系是怎么建立的。

------解决方案--------------------
打开项目里的“File.csproj”看看
XML code
 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
<PropertyGroup>
  <Configuration Condition=" '$(Configuration)' == '' ">Debug </Configuration>
  <Platform Condition=" '$(Platform)' == '' ">AnyCPU </Platform>
  <ProductVersion>8.0.50727 </ProductVersion>
  <SchemaVersion>2.0 </SchemaVersion>
  <ProjectGuid>{61F421EC-6FA1-4386-9CB9-BD1176EFFA32} </ProjectGuid>
  <OutputType>WinExe </OutputType>
  <AppDesignerFolder>Properties </AppDesignerFolder>
  <RootNamespace>File </RootNamespace>
  <AssemblyName>File </AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <DebugSymbols>true </DebugSymbols>
  <DebugType>full </DebugType>
  <Optimize>false </Optimize>
  <OutputPath>bin\Debug\ </OutputPath>
  <DefineConstants>DEBUG;TRACE </DefineConstants>
  <ErrorReport>prompt </ErrorReport>
  <WarningLevel>4 </WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <DebugType>pdbonly </DebugType>
  <Optimize>true </Optimize>
  <OutputPath>bin\Release\ </OutputPath>
  <DefineConstants>TRACE </DefineConstants>
  <ErrorReport>prompt </ErrorReport>
  <WarningLevel>4 </WarningLevel>
</PropertyGroup>
<ItemGroup>
  <Reference Include="System" />
  <Reference Include="System.Data" />
  <Reference Include="System.Deployment" />
  <Reference Include="System.Drawing" />
  <Reference Include="System.Windows.Forms" />
  <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
  <Compile Include="Form1.cs">
  <SubType>Form </SubType>
  </Compile>
  <Compile Include="Form1.Designer.cs">
  <DependentUpon>Form1.cs </DependentUpon>
  </Compile>
  <Compile Include="Program.cs" />
  <Compile Include="Properties\AssemblyInfo.cs" />
  <EmbeddedResource Include="Form1.resx">
  <SubType>Designer </SubType>
  <DependentUpon>Form1.cs </DependentUpon>
  </EmbeddedResource>
  <EmbeddedResource Include="Properties\Resources.resx">
  <Generator>ResXFileCodeGenerator </Generator>
  <LastGenOutput>Resources.Designer.cs </LastGenOutput>
  <SubType>Designer </SubType>
  </EmbeddedResource>
  <Compile Include="Properties\Resources.Designer.cs">
  <AutoGen>True </AutoGen>
  <DependentUpon>Resources.resx </DependentUpon> c_a_3();
  </Compile>
  <None Include="Properties\Settings.settings">
  <Generator>SettingsSingleFileGenerator </Generator>
  <LastGenOutput>Settings.Designer.cs </LastGenOutput>
  </None>
  <Compile Include="Properties\Settings.Designer.cs">
  <AutoGen>True </AutoGen>
  <DependentUpon>Settings.settings </DependentUpon>
  <DesignTimeSharedInput>True </DesignTimeSharedInput>
  </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>


你会发现
XML code
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon> 
</Compile>

<EmbeddedResource Include="Form1.resx">
<SubType>Designer</SubType> 
<DependentUpon>Form1.cs</DependentUpon> 
</EmbeddedResource> 

  • 本文相关:
  • c# 窗体之间相互控制的有关问题
  • C# winform程序中怎的实现tabcontrol控件中的tabpage动态的隔一段时间轮换一页
  • 继续请问C# Form有关问题,关于画表格
  • C# 联接csv文件
  • socket accept BeginAccept(.)解决方法
  • C#将指定位置跟长度的Byte数组转换为字符串
  • 64位win7上 Webbrowser控件不能正常显示加载的网页
  • C# 怎么创建集合
  • image转string解决办法
  • 问一个关于函数模板 <T>的用法解决方法
  • 免责声明 - 关于我们 - 联系我们 - 广告联系 - 友情链接 - 帮助中心 - 频道导航
    Copyright © 2017 www.zgxue.com All Rights Reserved