获取 vcproj 文件中 $(ProjectDir)、$(SolutionDir) 的值

发布于 2024-10-15 05:28:21 字数 173 浏览 0 评论 0原文

是否可以在 Visual Studio 之外以编程方式获取 $(ProjectDir)$(SolutionDir) 的值?我的情况是我需要将 vcproj 文件作为文本文件读取并获取其属性(如输出目录等)。问题是某些属性包含环境变量(如 $(SolutionDir) 等)。

Is it possible to get the value of $(ProjectDir) or $(SolutionDir) programatically outside Visual Studio? My scenario is I need to read a vcproj file as a text file and get its properties like the outputdirectory etc.. problem is some properties contain environment variables like $(SolutionDir) and the like.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟燃烟灭 2024-10-22 05:28:21

好吧,您发现仅查看 .vcproj 文件是不够的。您还需要了解 .sln 文件。在解决这个问题之前,你有点陷入困境。当 Visual Studio 加载 .vcproj 文件并且找不到匹配的 .sln 时,它始终会创建 .sln 文件。也许你也想这样做。

Well, you found out that looking at the .vcproj file isn't enough. You need to know the .sln file as well. You're kinda stuck until you resolve this. Visual Studio will always create a .sln file when it loads a .vcproj file and cannot find a matching .sln. Maybe you want to do that too.

玩物 2024-10-22 05:28:21

您实际上可以显示 Visual Studio 内部定义和使用的任何变量的值(以下步骤至少适用于 VS 2022),例如 $(SolutionDir)$(WindowsSDK_IncludePath)

  1. 打开解决方案属性(例如,从解决方案资源管理器)
  2. ,将打开一个名为your_sln_name Property Pages的对话框,
  3. 左侧面板中选择自定义构建步骤
  4. 在 右键,单击/选择名为命令行的行,
  5. 单击该行末尾出现的下拉箭头,
  6. 单击下面打开的短文本框(->“<编辑... .>")
  7. 另一个名为“命令行”的对话框打开,
  8. 现在您有两个选择:首先,您可以单击上方的大编辑框并输入要检查的变量,每行一个,例如输入
    $(WindowsSDK_IncludePath)
    $(ProjectDir)
  9. 然后您将看到实际值以交互方式显示在下部文本框中(标记为“评估值:”),例如
    C:\Program Files (x86)\Windows Kits...;C:\Program Files (x86)\ 等
    <您的解决方案/项目文件夹>
  10. 其次,您可以单击右下角的按钮
  11. ,该按钮会显示对话框的附加部分,其中包含 >(可滚动和可搜索!) 所有活动环境变量和 VS 内部变量的列表(按名称字母顺序排序)及其值

You can actually display the value of any variable defined and used internally by Visual Studio (steps below apply at least for VS 2022), like $(SolutionDir) or $(WindowsSDK_IncludePath):

  1. open your solution properties (e.g. from Solution Explorer)
  2. a dialog named your_sln_name Property Pages opens
  3. select Custom Build Step in the left panel
  4. on the right, click/select the line named Command Line
  5. click the drop down arrow that appears at the end of that line
  6. click into the short text box the opens beneath (-> "<Edit....>")
  7. another dialog opens named "Command Line"
  8. now you have two options: firstly, you can either click into the upper big edit box and enter the variables you want to inspect, one per line, e.g. enter
    $(WindowsSDK_IncludePath)
    $(ProjectDir)
  9. you will then see the actual values interactively displayed in the lower text box (labelled "Evaluated value:"), e.g.
    C:\Program Files (x86)\Windows Kits...;C:\Program Files (x86)\ etc.
    <your solution/project folder>
  10. secondly, you can click on the button Macros at the bottom right
  11. that causes an additional part of the dialog to appear which contains a (scrollable and searchable!) list of all active environment variables and VS-internal variables (alphabetically sorted by their names) along with their values
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文