107

I have a Visual Studio 2008 solution into which I have imported a number of pre-existing projects. The projects are mixed-language sample code (C#, VB, C++/CLI). They currently have multiple configurations, but I want each project only to have only a single "Debug" configuration.

In the configuration manager, I deleted the other configurations (e.g. "Release"), but as I did so there was a warning message to tell me that they would not be deleted from the individual projects.

And indeed when I navigate to an individual project, it still has "Release" and other configurations, even though at the solution level there is only "Debug".

How can I best remove these extra configurations from each project? Am I overlooking some way to do this in the GUI, or should I just edit the project files directly?

Eric
  • 11,392
  • 13
  • 57
  • 100

5 Answers5

213

In the Configuration Manager, select "Edit..." in the "Configuration" column for each project (not via the dropdown named Active solution configuration) that has configurations you want to remove.

In the dialog that pops up, mark each unwanted configuration and select "Remove".

Matthias
  • 4,481
  • 12
  • 45
  • 84
Timbo
  • 27,472
  • 11
  • 50
  • 75
  • 25
    Thank you! I wish Visual Studio offered a quicker way to remove a configuration across all projects. If you have a dozen projects or so in a solution it's a pain to go through each of them and manually delete the configuration. – Stefano Ricciardi Aug 23 '11 at 09:43
  • This does not remove anything from your project files. The configuration that must be deleted can be accessed by right clicking the project in the solution explorer and selecting properties. – Matthias Oct 11 '14 at 16:13
  • 1
    @Matthias I beg to differ. And no, it has not been changed (from when I answered this in 2009 up to version 2013). – Timbo Oct 11 '14 at 17:42
  • I agree with the answer for http://stackoverflow.com/questions/5832245/visual-studio-cant-remove-project-configurations – Matthias Oct 11 '14 at 17:57
  • 2
    If I go to the Configuration Manager, delete an active solution configuration via edit, then the configuration is indeed removed from the Configuration Manager. But If you now go to the properties of your project, then the configuration is still there. If you look inside the .vcxproj files, then the configuration is still there. I use Visual Studio 2013 (Professional and Ultimate) – Matthias Oct 11 '14 at 18:00
  • 1
    @Matthias Read carefully (especially the part _for each project_). Maybe the word choice/order in my answer is not properly optimized for best comprehensibility, but that does not change whether this works or not. – Timbo Oct 11 '14 at 18:07
  • My apologies, I used the dropdown in the headerbar instead of each dropdown separately. I edited the response in order to remove my downvote. – Matthias Oct 11 '14 at 18:14
  • 1
    @Stefano Ricciardi 5 years later, did you find a solution for such pain? – cppBeginner Feb 17 '18 at 09:31
  • @StefanoRicciardi I found a solution, see my answer here stackoverflow.com/a/57183031/1636173 – Giulio Caccin Jul 31 '19 at 11:27
17

The best way to automate the removal a configuration from all the projects of a solution is done by using Nuget console command to access visual studio apis.

Go to Tools, Nuget Package Manager, Package Manager Console.

From there use:

Get-Project -All | Foreach { $_.ConfigurationManager.DeleteConfigurationRow("Release") }

In this way you have removed all the configurations from all the projects called "Release". I strongly suggest you to always check the differences on your source code versioning sistem, you will see only csproj and in some cases sln files affected, if you are using configuration transformations (like Web.Release.config) they will still be there.

Further information are available on the visual studio version-specific api documentation here, this works from at least VS 2015 for C++, C#, F#, VB languages.

Giulio Caccin
  • 2,962
  • 6
  • 36
  • 57
  • Can you provide some reference e.g. how you come up with this code? Are there any tutorial? I want to make sure it will not break my project, be able to maintain it myself, and probably use it for other things. – javaLover Jul 31 '19 at 10:41
  • Thank! I noticed the topic's tree (top of page) in your link is `Docs > .NET > ... > DeleteConfigurationRow`. Does it work only for .net solution? Did you also test it for C++ solution? – javaLover Jul 31 '19 at 11:20
  • Didn't work in VS2019 on my C++ solution: Error HRESULT E_FAIL has been returned from a call to a COM component. At line:1 char:30 + ... | Foreach { $_.ConfigurationManager.DeleteConfigurationRow("DLL-Impor ... + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException Error HRESULT E_FAIL has been returned from a call to a COM component. At line:1 char:30 + ... | Foreach { $_.ConfigurationManager.DeleteConfigurationRow("DLL-Impor ... – Terry Apr 11 '20 at 14:41
  • 2
    Worked fine for me, solution of C++ projects. Thanks for the tip! – Nordic Mainframe Jul 09 '20 at 07:35
  • This worked fine for me when using VS2019 with C++ and C# projects. I'm so glad I found this post before having to use the GUI. I try to avoid VS2019 at all costs, and only end up really using it for debugging. @Giulio Caccin, do you happen to know if you can edit the name of pre-existing configurations via this API? I looked at the documentation and it wasn't particularly clear to me. – Andy Apr 22 '21 at 16:12
  • 1
    Just looked through the API again, and it looks like it isn't possible as the access method for the name of a collection is restricted to get https://learn.microsoft.com/en-us/dotnet/api/envdte.configurations.name?view=visualstudiosdk-2019#EnvDTE_Configurations_Name. – Andy Apr 22 '21 at 16:24
  • 1
    @Terry - I managed to get this error but it occured on a project that was created in an older version of Visual Studio and hadn't been updated. This might also be the issue that was affecting you. – Andy Apr 22 '21 at 16:51
  • I arrived too late @Andy, happy I helped you a bit! – Giulio Caccin Apr 26 '21 at 06:24
15

To help illustrate timbo's answer, here is what he's talking about. Like some of the commenters it took me a while to find this.

enter image description here

Tom Winter
  • 1,813
  • 3
  • 18
  • 23
3

Doesn't answer this particular question I know but with VS2013 you can open the Property Manager tab, expand all project configurations, do multiple selection using the CTRL or SHIFT keys and delete configurations from multiple projects at once.

scott_ish
  • 31
  • 3
  • Is this for C++ projects only? I guess the tab you are referring to is the 'View>Other Windows>Property Manager'? – Steven Anderson Oct 29 '15 at 02:10
  • This worked perfectly in VS2017. I only wanted to keep two C++configurations (Debug|Release+Win32|x64) across multiple projects so I expanded all of the projects in the Property Manager, clicked the top configuration, scrolled to the bottom and shift-clicked the bottom configuration and then used control-click to de-select the configurations to keep. You must also de-select the names of the projects or delete will not appear in the menu. Then right-click on a selected (not de-selected) configuration and select Remove. Finally, go to Project->Configuration manager and remove the configurations. – UweBaemayr Oct 07 '21 at 18:34
1

In VS2017/VS2019, if you drop down the "Active solution configuration", there is an <edit> there that lets you remove a configuration from all projects.

Screenshot showing <edit>

PolicyWatcher
  • 447
  • 2
  • 5