4

In my VSIX (VS Extension), I am reading the config properties' .Value of each of the projects in the currently loaded solution. For a C# (csproj) project:

var configurationManager = project.ConfigurationManager;
if (configurationManager == null) return null;
var configuration = configurationManager.ActiveConfiguration;
if (configuration == null) return null;
var properties = configuration.Properties;
if (properties == null) return null;

foreach (var property in properties.Cast<Property>())
{
    // reading property.Name is OK but reading property.Value gives the COMException 'not implemented'
    if (property == null) continue;
    if (property.Name == "StartWorkingDirectory") workingDir = (string)property.Value;
    if (property.Name == "StartAction") startProject = 0 == (int)property.Value;
    if (property.Name == "StartProgram") startExtProg = (string)property.Value;
    if (property.Name == "StartURL") startBrowser = (string)property.Value;
    // etc...
}

For every property, I get the COMException: 'The method or operation is not implemented' when I try to read the .Value property, though .Name is fine. All the searched for properties seem to exist, their .Value just can't be read.

This is a brand new VSIX project created with the VS2022 template that includes Microsoft.VisualStudio.SDK and the Microsoft.VisualStudio.BuildTools in the references.

That seems to include every DTE* reference, stdole, and the other VS COM dlls like VSLangProj* (If I try to add these as project references, it says they're already included in the build process). So, I tried adding all those references via nuget packages, but it had no effect I could see and the error remains.

So I can't find anything on how to read these properties on my C# projects (csproj). They're simple C# 8 Console applications, empty that I just created.

Here are all my VSIX project's references, including the ones pulled in by nuget but probably don't need to be:

envdte
envdte80
envdte90
Microsoft.CSharp
Microsoft.VisualStudio.CommandBars
Microsoft.VisualStudio.SDK
Microsoft.VSSDK.BuildTools
NJsonSchema
PresentationCore
PresentationFramework
stdole
System
VSLangProj
VSLangProj100
VSLangProj110
VSLangProj140
VSLangProj150
VSLangProj80
VSLangProj90
WindowsBase
WindowsFormsIntegration

I'm using VS2022, fully updated as of March 2024.

Any ideas?

EDIT: Source at: https://github.com/cbordeman/switchstartupproject/pull/4

5
  • Is this issue only occurs on new vs version or also in the old version of vs? Commented Mar 5, 2024 at 3:11
  • @BowmanZhu-MSFT I don't know, the extension won't load at all on VS2019. The described error occurs when debugging against VS2022. Commented Mar 7, 2024 at 13:19
  • I've added the link to my fork on Github. Commented Mar 7, 2024 at 13:21
  • Is the Property in properties.Cast<Property>() DEFINATELY EnvDTE.Property? Do you get same behavior if you use OfType<> not Cast<>? Commented Mar 12, 2024 at 15:22
  • @tolanj It is definitely EnvDTE.Property. Using .Name works, .Value throws the exception. Commented Mar 17, 2024 at 17:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.