c# - 如何在没有 visual studio 的情况下将新文件添加到 .csproj 文件

标签 c# .net visual-studio

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

最佳答案

我认为没有任何工具可以响应命令行上的“add-project”命令来执行此操作,但我认为您可能会幸运地创建一个程序/脚本来操作 csproj 的 XML 内容直接文件。

csproj 文件的结构如下所示:

<?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 元素即可:

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

如果您使用现有的项目文件作为模板,这应该可以通过非常简单的 XSLT 实现。

关于c# - 如何在没有 visual studio 的情况下将新文件添加到 .csproj 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14382974/

相关文章:

c# - 在 Skip and Take 发生之前从 LinqDataSource 检索数据?

xml - 如何将 XML 元素添加到 Visual Studio 2010 RC 中的工具箱中

c# - EditorFor type=date,只显示掩码

.net - Dapper GridReader 已处理错误

c# - 标记枚举与常规枚举的 HashSet

visual-studio - 如何 merge 资源文件?

python-2.7 - Visual Studio Code : No tests discovered, 请检查测试的配置设置

c# - ASP.NET 动态添加列到 Gridview

c# - Entity Framework 中相同类型的多个集合

c# - 内部类序列化为xml