How can I add a new file to .csproj
from command prompt?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Here's an easy way you can do it using Linq2Xml. I've included a single and a list based method. Oh, and like Casper said: you'll need to unload the project from VS before your program can edit it. Then just reload it when done.
.csproj files can be used as input into the MSBuild command line tool.
See the MSBuild reference:
MS Build Reference
And for example, this question.
MSBuild — Use the .csproj file or roll your own?
You can simply use a text editor to edit them and do anything MSBuild allows. If you insert custom build actions Visual Studio might warn a developer when the project is loaded that it contains custom actions, depending on what you do.
Unload the project by right clicking it in solution explorer. Edit the project by right clicking. Add f.ex:
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.
The structure of a csproj file looks like this:
To add a C# code file to a project, you just need to add a
Compile
element to anItemGroup
element:If you use an existing project file as a template, this should be possible with a very simple XSLT.