2012-11-14 72 views
13

我想将包含xaml和cs文件以及其他目录的文件夹添加到VS上的其他项目。由于某些原因,当我将文件夹从Windows资源管理器拖到我想放置该目录的项目时,Visual Studio不会让我。因为这是我手动添加每个文件,每次遇到一个目录我都要创建它。也许这是因为我使用团队基础服务器。将现有的xaml文件添加到visual studio 2012

反正我手动添加文件,所以我点击文件夹,我想在Visual Studio中添加文件,然后单击添加现有文件。然后,我选择了XAML和代码隐藏文件:

enter image description here

当我点击添加文件被添加,但视觉工作室不承认Bytes.xaml.cs是后面的代码!

enter image description here

我必须手动添加窗口,然后复制并粘贴文件的内容?

回答

20

编辑您的.csproj文件,添加下面的“编译”元素的“DependentUpon”元素为.xaml.cs文件,以便它会出现“内部”的.xaml文件不是简单地在它下面:

<Compile Include="BytesDisplay\SubControls\Bytes.xaml.cs"> 
    <DependentUpon>Bytes.xaml</DependentUpon> 
</Compile> 

要轻松编辑.csproj的文件:

Right-click the project and select "Unload Project" 
Right-click the project node again and select "Edit [projectname].csproj" 
Edit the XML, then close the file 
Right-click the project node again and select "Reload Project" 
0

感谢写了。如果您编辑xaml和.cs文件类声明以在没有类冲突的情况下进行匹配 - 那么当您添加.xaml文件时,如果它位于同一文件夹中,它将自动拾取.xaml.cs。 (vs 2013)

2

如果您将.xaml文件从Windows资源管理器拖放到Solution Explorer窗口,它将自动添加.xaml和代码隐藏的.cs文件。

+1

这比接受的答案容易得多。如果您已经添加了这些文件,只需从项目中排除它们,然后从Windows资源管理器中拖放即可。也适用于VS 2017。 – CtrlDot

相关问题