如何从命令提示符向 .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/