如何在不使用Visual Studio的情况下将新文件添加到.csproj文件 [英] How can I add a new file to .csproj file without visual studio

查看:275
本文介绍了如何在不使用Visual Studio的情况下将新文件添加到.csproj文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从命令提示符下将新文件添加到.csproj?

How can I add a new file to .csproj from command prompt?

推荐答案

我认为没有任何工具可以响应命令行上的"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.

这篇关于如何在不使用Visual Studio的情况下将新文件添加到.csproj文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆