读书人

Visual Studio 里怎么把partial class

发布时间: 2012-08-09 15:59:21 作者: rapoo

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>


</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#

热点推荐