Getting access to Project Properties

Apr 26, 2013 at 8:58 PM

When you have a project within a solution that is a "Web Application" project, there is a property called "Always Start When Debug". Having done:

$project = Get-Item .\WebApplication1

How would I go about getting access to this property?

Also, what is the best way of looking up the available properties, assuming that they aren't exposed directly through StudioShell?


Apr 27, 2013 at 5:09 PM
Hey again, you've been busy Gary...

You'll find those properties in the /projectproperties folder of the project; e.g.,:

dir DTE:\solution\projects\SuperAwesomeWebsite\ProjectProperties;

You can use set-item to set the value for any of the properties; the one you're after is "WebApplication.StartWebServerOnDebug:"
set-item DTE:\solution\projects\SuperAwesomeWebsite\ProjectProperties\WebApplication.StartWebServerOnDebug -value $false #or $true
Apr 27, 2013 at 5:58 PM

Aw man, you have no idea! I keep thinking of more and more things that I can use StudioShell for :-)

That looks perfect, thanks! Now, a follow up question...

What would be the best way to select all of the WebApplication Projects from a given solution? We have a reasonably large solution, and there is a mixture of Windows Application, Web Applications, etc within the solution. Obviously, this property doesn't exist all project types.


Apr 29, 2013 at 1:30 PM

Okay, I have to say, this has got me stumped!

I can't find a way to do the following:

For the given solution, enumerate all the Projects, and if that project is of type WebApplication, or rather, has the WebApplication.StartWebServerOnDebug property, set this property to false.

Any chance someone can provide an example of doing this?


May 3, 2013 at 2:07 PM
I'm spitballing here, but based on our previous exchanges on this thread, I see no reason something like this wouldn't work:
cd DTE:\solution\projects;
dir | where { 
  test-path $_\ProjectProperties\WebApplication.StartWebServerOnDebug 
} | foreach {
  set-item $_\ProjectProperties\WebApplication.StartWebServerOnDebug -value $false #or $true
May 3, 2013 at 10:22 PM
Hello there,

Thanks for getting back to me! Yes, this looks like exactly what I want, and it is essentially what I was trying, but I can't for the life of me get it to work.

I have a solution open in Visual Studio that has two Web Applications, and a Windows Application.

If I try to run the above script, I get no results returned. It seems to be the case that once piped through, the result of the dir, doesn't seem to be the correct "context", if that is the right word.

If I do the following:
cd DTE:\Solution\Projects\WebApplication1;
Test-Path ProjectProperties\WebApplication.StartWebServerOnDebug
I will get a result of True. And when I do:
cd DTE:\Solution\Projects\WindowsApplication1;
Test-Path ProjectProperties\WebApplication.StartWebServerOnDebug
I will get a result of false, which is exactly as expected.

However, even running this:
cd DTE:\Solution\Projects;
dir | where { Test-Path $_\ProjectProperties\WebApplication.StartWebServerOnDebug }
Returns no results.

I have tried all the various combinations of things that I can think of, but I can get anything to work.

Any ideas?


May 4, 2013 at 11:54 AM
Herp derp, by bad... I forgot that StudioShell doesn't return the item path from the ToString method of the DTE wrappers. No matter...
dir | where { Test-Path "$( $_.pspath )\ProjectProperties\WebApplication.StartWebServerOnDebug" }
See if that gets you moving. The $() in the string tells PowerShell to evaluate the expression when interpolating the string.
May 4, 2013 at 12:54 PM
Hey Jim,

That did it! :-)

Completed script being:
dir | where { 
    Test-Path "$( $_.pspath )\ProjectProperties\WebApplication.StartWebServerOnDebug" 
} | foreach { 
    Set-Item "$( $_.pspath )\ProjectProperties\WebApplication.StartWebServerOnDebug" -value $false 

May 4, 2013 at 2:07 PM
Hello again,

Ok, I have this working, to an extent, but now I am looking to extend it slightly more :)

Within a Solution, we sometimes use Solution Folders to group different projects together. I thought I had read that doing dir on dte:/Solution/Projects would return all the Projects within the Solution, regardless of their "Location", i.e. nested within a Solution Folder, but this doesn't seem to be the case. Did I pick this up wrong, or am I doing something incorrect?


May 6, 2013 at 1:10 PM
Technically solution folders are projects to Visual Studio; the DTE:/solution/projects and dte:/solution/codemodel nodes include them. It is a PITA; I've considered adding custom -filter for dir at those nodes that would return specific types, but the recursive traversal is expensive. I'm more inclined to add a "get-project" cmdlet to ss.contrib that would match by name, language, project type, etc.
May 6, 2013 at 2:10 PM

Gotcha, thinking about it, that makes sense.

I have added an issue to the backlog: