Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a Property to ENVDTE.Project

I'm trying to work on a Visual Studio Extension that needs to add a property that gets persisted to the current csproj file like so:

    <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <MyProperty Condition="$(MyProperty) == '' Or $(MyProperty) == '*Undefined*'">MyPropertyValue</MyProperty>

I have an ENVDTE.Project instance, but can't seem to find anywhere in the API to add a new property to the project.

I'm able to work around the issue by converting it to an MSBuild project and adding the property that way, but that approach causes the user to get prompted that the csproj file has been modified outside of the IDE and asks them to re-load, which I don't want.

How can I either add the property with the ENVDTE.Project instance, or prevent the 'Modified outside the environment' prompt from showing up in some other way?

like image 725
Craig Vermeer Avatar asked Dec 18 '25 20:12

Craig Vermeer


1 Answers

Got my issue resolved with the MSBuild project workaround.

The issue that was causing the user to get prompted that the project file had changed was that I was calling .Save() on my MSBuild project object, and not my ENVDTE project object.

like image 160
Craig Vermeer Avatar answered Dec 22 '25 00:12

Craig Vermeer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!