Visual Studio Extension:以编程方式翻译$(XXX)

时间:2017-06-30 07:15:27

标签: c# visual-studio visual-studio-2017 visual-studio-extensions

我尝试为VisualStudio 2017进行扩展。

目前,我没有找到使用C#和Visual.VCProject API以编程方式翻译$(XXX)(通过示例$(SolutionDir)或$(TargetName))的方法。

EnvDTE.Project project = (EnvDTE.Project)selectedProjects.GetValue(0);
var vcproj = project.Object as VCProject;
VCConfiguration cfg = (VCConfiguration)vcproj.ActiveConfiguration;
VCDebugSettings debug = (VCDebugSettings)cfg.DebugSettings;

string path = debug.WorkingDirectory;
// Here path is $(ProjectDir) But I need something like c:\myProject
// Resolution can be done because Visual can do: my question is : How ?

你有什么想法吗?

参考文献& DOC:

https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.vcconfiguration.debugsettings.aspx

编辑:经过一些搜索

我在doc中找到了一些关于$()

的解释

https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-reference-the-name-or-location-of-the-project-file

可能是回复是在这部分文档中吗?

https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsbuildpropertystorage(v=vs.140).aspx

https://docs.microsoft.com/fr-fr/visualstudio/extensibility/internals/persisting-data-in-the-msbuild-project-file

https://docs.microsoft.com/fr-fr/visualstudio/extensibility/internals/using-msbuild

1 个答案:

答案 0 :(得分:1)

使用VCConfiguration.Evaluate评估项目模型或环境宏的值

EnvDTE.Project project = (EnvDTE.Project)selectedProjects.GetValue(0);
var vcproj = project.Object as VCProject;
VCConfiguration cfg = (VCConfiguration)vcproj.ActiveConfiguration;
VCDebugSettings debug = (VCDebugSettings)cfg.DebugSettings;

//string path = debug.WorkingDirectory;
string path = cfg.Evaluate(debug.WorkingDirectory);

// Here path is $(ProjectDir) But I need something like c:\myProject
// Resolution can be done because Visual can do: my question is : How ?