如何在C#中使用microsoft.build.evaluation.project获取实际项目输出 [英] How to get actual project output using microsoft.build.evaluation.project in c#
问题描述
我需要知道项目中实际输出文件名的完整路径。
我使用microsoft.build.evaluation.project打开具有正确属性的项目,并且尝试使用属性TargetPath,TargetDir,TargetFileName,但是我找不到一致的属性来给我输出文件名与路径。
在某些项目中有效,在某些项目中无效。我同时处理csproj文件和vcxproj文件。
I need to know the actual output file name full path in a project. I use microsoft.build.evaluation.project to open a project with the correct properties, and i tried using the properties TargetPath, TargetDir, TargetFileName, but i can't find a consistent property to give me the output file name with the path. In some projects it works, and in some it doesn't. I work both on csproj files and vcxproj files.
推荐答案
输出路径与项目文件夹相关。您可以通过属性 OutputPath
从项目文件中获取其值(假设 project
是的实例) Microsoft.Build.Evaluation.Project
)
Output path is related to project folder. You can get its value from project file via property OutputPath
(suppose project
is an instance of Microsoft.Build.Evaluation.Project
)
var outputPath = project.GetPropertyValue("OutputPath")
然后您可以使用Path.Combine连接输出路径和项目文件夹
Then you can use Path.Combine to concatenate your output path and project folder
var fullpath = Path.Combine(projectDirectory, outputPath);
这篇关于如何在C#中使用microsoft.build.evaluation.project获取实际项目输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!