question

TobyCharlton-6413 avatar image
0 Votes"
TobyCharlton-6413 asked AnnaXiu-MSFT answered

Is there a way to save EnvDTE Project global variables to the vcxproj.user file rather than the .vcxproj file?

As the title states, I'm trying to save data to the user file (projectname.vcxproj.user) rather than the project file (projectname.vcxproj)

Reading the variable (or initialising it) is done like this:

 var globals = project.Globals;
    
 string readValue = "";
    
 if (!globals.VariableExists["variablename"])
 {
     globals.VariablePersists["variablename"] = true;
 }
 else
 {
     readValue = (string)globals["variablename"];
 }

and writing the data is done with this line

 var globals = m_project.Globals;
 globals["variablename"] = "write this value";

However, the data gets written into the .vcxproj file as

   <ProjectExtensions>
     <VisualStudio>
       <UserProperties variablename="write this value" />
     </VisualStudio>
   </ProjectExtensions>

rather than into the .vcxproj.user file.

Is it possible to write to .vcxproj.user instead?




vs-extensions
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AnnaXiu-MSFT avatar image
1 Vote"
AnnaXiu-MSFT answered

Hi @TobyCharlton-6413 ,

Welcome to Microsoft Q&A!

Which version of Visual Studio are you using?

For the Project.Globals object, the variable is retained by the environment in the project file.
I suppose the data cannot be written to .vsxproj.user file.

Sincerely,
Anna


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.