lucasbrendel
lucasbrendel

Reputation: 506

Adding project to solution through command line

I have a Visual studio solution that is made up of multiple test projects. Each project is a copy of a template project. When the template project is copied there is a batch script that is ran that does some file renamings and adds a couple other specified files. What i would like to do is then have the project added to the solution during that process. I was looking at devenv switches here on MSDN but i am not seeing anything about adding a project to a solution.

Is adding a project to a solution possible through the command line?

Thanks

Upvotes: 3

Views: 3613

Answers (3)

Jay
Jay

Reputation: 604

If you are here after 2019 and using Asp.Net Core. Here is the way to do it:

dotnet sln yoursolution.sln add yourprojectpath/yourproject.csproj

Upvotes: 6

David Brabant
David Brabant

Reputation: 43499

If you don't mind writing a bit of PowerShell, you can do this pretty easily. First, read this question and its answers. You'll find a pointer to a nuget package (Microsoft.SQLServer.Compact) which includes PowerShell scripts to automate VS through its object model. This is a good place to start to have some examples of how to handle a solution file from PowerShell. Then you write a small PowerShell script using the SolutionFolder.AddFromFile to add your project to your solution. This might be even easier using StudioShell and its provider, but I haven't tried it yet.

Upvotes: 4

lavrik
lavrik

Reputation: 1474

For sln file try this question. For project file you can run some xslt or any other necessary transform to edit. For example you can create MSBuild proj file to run xslt transform over desired sln file and then run it in cmd like: MSBuild.exe MyProj.proj. The sample content of MyProj.proj is like:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Transform">
    <TransformXml Source="Project.csproj" Transform="Transform.xml" Destination="New_Project.csproj" />
  </Target>
</Project>

Upvotes: -1

Related Questions