日期:2014-05-18  浏览次数:20899 次

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 &