且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不使用Visual Studio的情况下将新文件添加到.csproj文件

更新时间:2023-09-20 12:27:46

我认为没有任何工具可以响应命令行上的"add-project"命令,但是我认为您可以幸运地创建了一个程序/脚本来直接处理csproj文件的XML内容.

I don't think there's any tool that will respond to an "add-project" command on the command-line to do this, but I think you could have luck creating a program/script to manipulate the XML content of csproj files directly.

csproj文件的结构如下:

The structure of a csproj file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="...">
    <PropertyGroup>
        <!-- Properties which affect the build process -->
    </PropertyGroup>
    <ItemGroup>
        <!-- Groups of items to process -->
    </ItemGroup>
</Project>

要将C#代码文件添加到项目,只需将Compile元素添加到ItemGroup元素:

To add a C# code file to a project, you just need to add a Compile element to an ItemGroup element:

<Compile Include="{relative path to file}" />

如果您将现有的项目文件用作模板,则可以通过非常简单的XSLT来实现.

If you use an existing project file as a template, this should be possible with a very simple XSLT.