visual-studio-extensionsvsixenvdte

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?


Solution

  • There is few information about .vcxproj.user file, you may have read this doc: .user files and why they are problematic or this doc: .vcxproj.user files.

    Normally, the properties are set/stored in .xxproj file by default these days. Due to some reasons, the .user file is used for specific properties, or under specific circumstance.

    I believe the global variables are written to the .vcxproj file by default, and it is not possible to write the global variables to the .vcxproj.user file.