我尝试为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:
编辑:经过一些搜索
我在doc中找到了一些关于$()
的解释可能是回复是在这部分文档中吗?
https://docs.microsoft.com/fr-fr/visualstudio/extensibility/internals/using-msbuild
答案 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 ?