将元素添加到 xml 文件
我正在尝试从 C# .csproj 文件添加和删除元素。该文件的部分内容如下所示。有人可以告诉我如何做以下两件事吗?
- 添加一个元素,如下所示(该行显示“我想添加 this")
- 删除一个元素。例如,假设我想删除 I 行 已在下面指出。
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
</ItemGroup>
<ItemGroup>
<Compile Include="Generate\DatabaseContext.cs" />
<Compile Include="Generate\EntityClasses.cs" />
<Compile Include="Generate\Extensions.cs" />
<Compile Include="Schema\Column.cs" />
<Compile Include="Schema\EntityRef.cs" />
<Compile Include="SerializedData\Tables.xml" /> //I want to add this
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
I am trying to add and delete elements from a C# .csproj file. The file, in part, appears below. Can someone show me how I can do the following two things?
- Add an element as shown below (the line that says, "I want to add
this") - Delete an element. For example, say I wanted to delete the line I
have indicated below.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
</ItemGroup>
<ItemGroup>
<Compile Include="Generate\DatabaseContext.cs" />
<Compile Include="Generate\EntityClasses.cs" />
<Compile Include="Generate\Extensions.cs" />
<Compile Include="Schema\Column.cs" />
<Compile Include="Schema\EntityRef.cs" />
<Compile Include="SerializedData\Tables.xml" /> //I want to add this
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过以下方式添加指示行:
要删除指示行,请尝试以下操作:
You can add your indicated line in the following way:
To remove your indicated line, try this:
我想这应该没问题
Ithink this should be fine