{"id":13008,"date":"2025-08-01T06:13:54","date_gmt":"2025-08-01T06:13:54","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=13008"},"modified":"2025-08-01T06:13:54","modified_gmt":"2025-08-01T06:13:54","slug":"add-project-to-solution-under-solution-using-dotnet-cli","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/dot-net\/add-project-to-solution-under-solution-using-dotnet-cli","title":{"rendered":"Add Project (.csproj) to Solution (.sln) Under Solution Folder Using Dotnet CLI"},"content":{"rendered":"<p>you can add a .csproj to a .sln file easily with the dotnet sln add command:<\/p>\n<p>dotnet sln todo.sln add todo-app\/todo-app.csproj<\/p>\n<p>if you want to <strong>place the project under a specific solution folder<\/strong> (like how Visual Studio organizes projects within folders in the Solution Explorer), you\u2019ll need to use an additional option that isn&#8217;t directly available in the standard dotnet CLI.<br \/>\nHere\u2019s a workaround using the dotnet sln CLI:<\/p>\n<h2>Step-by-Step Solution:<\/h2>\n<ul>\n<li><strong>Manually create the solution folder structure<\/strong> inside your .sln file using a text editor or Visual Studio (if possible).<\/li>\n<li><strong>Use the dotnet sln add command<\/strong> along with a workaround using Visual Studio commands (devenv) if you&#8217;re on Windows, or manually move the project in the .sln file.<\/li>\n<\/ul>\n<h2>Option 1: Manually Edit .sln File (Cross-platform workaround)<\/h2>\n<p>After running the command:<br \/>\n<code>dotnet sln todo.sln add todo-app\/todo-app.csproj<\/code><\/p>\n<p>Open todo.sln in a text editor and look for the project entry:<br \/>\n<code>Project(\"{GUID}\") = \"todo-app\", \"todo-app\/todo-app.csproj\", \"{PROJECT_GUID}\"<br \/>\nEndProject<\/code><\/p>\n<p>To place it under a solution folder, first declare a solution folder:<br \/>\n<code>Project(\"{66A26720-8FB5-11D2-AA7E-00C04F688DDE}\") = \"MySolutionFolder\", \"MySolutionFolder\", \"{FOLDER_GUID}\"<br \/>\nEndProject<\/code><\/p>\n<p>Then add the nesting relationship in the GlobalSection(NestedProjects) part of the file:<\/p>\n<h2>Option 2: Use Visual Studio (Windows Only)<\/h2>\n<p>If you&#8217;re on Windows, you can use the devenv command line to open the solution in Visual Studio and add the project to a solution folder there. <\/p>\n<h2>Summary<\/h2>\n<p>While the .NET CLI (dotnet sln add) does not support adding a project under a solution folder directly, you can work around this limitation by manually editing the .sln file or using Visual Studio.<\/p>\n<div class=\"qanda-read-box\"><div class=\"bg-light read-more-icon\"><img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/04\/24061434\/read-txt.png\" alt=\"Also Read\"><p><\/p><h3>Also Read:<\/h3><a href=\"https:\/\/www.bacancytechnology.com\/blog\/top-dot-net-core-libraries-list\" target=\"_blank\">.NET Core Libraries<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>you can add a .csproj to a .sln file easily with the dotnet sln add command: dotnet sln todo.sln add todo-app\/todo-app.csproj if you want to place the project under a specific solution folder (like how Visual Studio organizes projects within folders in the Solution Explorer), you\u2019ll need to use an additional option that isn&#8217;t directly [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13009,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[20],"tags":[],"class_list":["post-13008","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dot-net"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/13008"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=13008"}],"version-history":[{"count":3,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/13008\/revisions"}],"predecessor-version":[{"id":13012,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/13008\/revisions\/13012"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/13009"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=13008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=13008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=13008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}