c++ - Why is the project file name (only) sometimes prepended to the MSBuild intermediate directory? - Stack Overflow

In my builds, I need to ensure a specific intermediate directory. Now, I have noticed that building a .

In my builds, I need to ensure a specific intermediate directory. Now, I have noticed that building a .vcxproj file uses a different intermediate directory than building the same project as part of an .sln file: in fact, the former has the project file name prepended as an additional level while the latter does not.

In debugging this, I found that the intermediate directories differs between .vcxproj files in the .sln's folder (which do have the project name prepended) and .vcxproj files elsewhere (which do not).

Why is that, where is this documented, and how can I configure this to stay constant?

The documentation I found says that

$(IntDir): Path to the directory specified for intermediate files. If it's a relative path, intermediate files go to this path appended to the project directory.

I assume that "the project directory" is $(ProjectDir) which does not differ between builds, so I have no explanation why the $(IntDir)s do.

Here's an MWE to reproduce the problem:

Project.vcxproj

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns=";>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{00000000-0000-0000-0000-000000000001}</ProjectGuid>
  </PropertyGroup>
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Configuration">
    <PlatformToolset>v143</PlatformToolset>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Sub\Project.vcxproj

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns=";>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{00000000-0000-0000-0000-000000000002}</ProjectGuid>
  </PropertyGroup>
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Configuration">
    <PlatformToolset>v143</PlatformToolset>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Solution.sln

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RootProject", "Project.vcxproj", "{00000000-0000-0000-0000-000000000001}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SubProject", "Sub\Project.vcxproj", "{00000000-0000-0000-0000-000000000002}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|x64 = Debug|x64
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {00000000-0000-0000-0000-000000000001}.Debug|x64.ActiveCfg = Debug|x64
        {00000000-0000-0000-0000-000000000001}.Debug|x64.Build.0 = Debug|x64
        {00000000-0000-0000-0000-000000000002}.Debug|x64.ActiveCfg = Debug|x64
        {00000000-0000-0000-0000-000000000002}.Debug|x64.Build.0 = Debug|x64
    EndGlobalSection
EndGlobal

Build.bat

@echo off

pushd "%~dp0"
if "%VSCMD_VER%" == "" (
    call "%VS2022INSTALLDIR%\Common7\Tools\VsDevCmd.bat" -arch=amd64
)

set CMD=MSBuild.exe -v:diag -property:Configuration=Debug -property:Platform=x64
set GREP=findstr /b /c:"IntDir ="

%CMD% Solution.sln -target:RootProject | %GREP%
%CMD% Solution.sln -target:SubProject  | %GREP%
%CMD% Project.vcxproj                  | %GREP%
%CMD% Sub\Project.vcxproj              | %GREP%

Output

IntDir = Project\x64\Debug\
IntDir = x64\Debug\
IntDir = Project\x64\Debug\
IntDir = Project\x64\Debug\

dir *.lastbuildstate /s/b (expecting two files, finding three)

.\Project\x64\Debug\Project.tlog\Project.lastbuildstate
.\Sub\Project\x64\Debug\Project.tlog\Project.lastbuildstate
.\Sub\x64\Debug\Project.tlog\Project.lastbuildstate

In my builds, I need to ensure a specific intermediate directory. Now, I have noticed that building a .vcxproj file uses a different intermediate directory than building the same project as part of an .sln file: in fact, the former has the project file name prepended as an additional level while the latter does not.

In debugging this, I found that the intermediate directories differs between .vcxproj files in the .sln's folder (which do have the project name prepended) and .vcxproj files elsewhere (which do not).

Why is that, where is this documented, and how can I configure this to stay constant?

The documentation I found says that

$(IntDir): Path to the directory specified for intermediate files. If it's a relative path, intermediate files go to this path appended to the project directory.

I assume that "the project directory" is $(ProjectDir) which does not differ between builds, so I have no explanation why the $(IntDir)s do.

Here's an MWE to reproduce the problem:

Project.vcxproj

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft/developer/msbuild/2003">
  <PropertyGroup Label="Globals">
    <ProjectGuid>{00000000-0000-0000-0000-000000000001}</ProjectGuid>
  </PropertyGroup>
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Configuration">
    <PlatformToolset>v143</PlatformToolset>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Sub\Project.vcxproj

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft/developer/msbuild/2003">
  <PropertyGroup Label="Globals">
    <ProjectGuid>{00000000-0000-0000-0000-000000000002}</ProjectGuid>
  </PropertyGroup>
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Configuration">
    <PlatformToolset>v143</PlatformToolset>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Solution.sln

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RootProject", "Project.vcxproj", "{00000000-0000-0000-0000-000000000001}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SubProject", "Sub\Project.vcxproj", "{00000000-0000-0000-0000-000000000002}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|x64 = Debug|x64
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {00000000-0000-0000-0000-000000000001}.Debug|x64.ActiveCfg = Debug|x64
        {00000000-0000-0000-0000-000000000001}.Debug|x64.Build.0 = Debug|x64
        {00000000-0000-0000-0000-000000000002}.Debug|x64.ActiveCfg = Debug|x64
        {00000000-0000-0000-0000-000000000002}.Debug|x64.Build.0 = Debug|x64
    EndGlobalSection
EndGlobal

Build.bat

@echo off

pushd "%~dp0"
if "%VSCMD_VER%" == "" (
    call "%VS2022INSTALLDIR%\Common7\Tools\VsDevCmd.bat" -arch=amd64
)

set CMD=MSBuild.exe -v:diag -property:Configuration=Debug -property:Platform=x64
set GREP=findstr /b /c:"IntDir ="

%CMD% Solution.sln -target:RootProject | %GREP%
%CMD% Solution.sln -target:SubProject  | %GREP%
%CMD% Project.vcxproj                  | %GREP%
%CMD% Sub\Project.vcxproj              | %GREP%

Output

IntDir = Project\x64\Debug\
IntDir = x64\Debug\
IntDir = Project\x64\Debug\
IntDir = Project\x64\Debug\

dir *.lastbuildstate /s/b (expecting two files, finding three)

.\Project\x64\Debug\Project.tlog\Project.lastbuildstate
.\Sub\Project\x64\Debug\Project.tlog\Project.lastbuildstate
.\Sub\x64\Debug\Project.tlog\Project.lastbuildstate
Share Improve this question edited Nov 18, 2024 at 19:53 bers asked Nov 18, 2024 at 12:03 bersbers 6,0132 gold badges46 silver badges87 bronze badges 5
  • You haven't provided a MWE - emphasis on working. The projects you have provided as examples, fail to build because they do not contain a Configuration/Platform. The targets RootProject and SubProject don't exist -- which would be an error if Debug/x64 existed. You are relying on the diagnostic output (which outputs "initial properties", not property values as used) instead of what a working project actually produces as an intermediate directory. When built via the solution the properties reported by -v:diag include the property values as the solurtion sees them. – Jonathan Dodds Commented Nov 18, 2024 at 17:05
  • @JonathanDodds it shouldn't really matter: the IntDir values that are output are consistent with what I observe when compiling an actual project. Also, if you are right, I can easily change my question to "why are 'initial properties' different ...?" Either way, I will update the answer with a completely MWE. – bers Commented Nov 18, 2024 at 19:43
  • The 'initial properties' can be different because the properties are changed during evaluation. If you have a variable set to 0 and then change the value to 1 before using the variable, do you complain that the initial value was 0? – Jonathan Dodds Commented Nov 19, 2024 at 2:19
  • @JonathanDodds I am not complaining about the initial property values (assuming you are right that these are different from the final ones). I am complaining about the final location where intermediate files are being stored to, and that location is inconsistent: see the dir output in the updated question. Now, it so happens that the initial location equals the final location, so my hypothesis is that the initial location needs to be fixed. If you know another way to fix the final location, by all means, please go ahead. – bers Commented Nov 19, 2024 at 6:04
  • 1 I tested with your revised MWE (except that I didn't bother with the Build.bat file) and I can see that the directories are created as you say. I think your own answer is on-point -- This is a somewhat recent change in behavior that is a somewhat poorly executed fix for an issue. – Jonathan Dodds Commented Nov 19, 2024 at 17:26
Add a comment  | 

1 Answer 1

Reset to default 1

Somewhat hypothetical/heuristical answer:

Why is that?

I think this is primarily to avoid warning MSB8028 ("The intermediate directory (shared-intermediate-path) contains files shared from another project (intermediate-path).")

If so, this somewhat poorly executed, since putting projects in subdirectories does not guarantee they do not share intermediate directories. But I understand the assumption may be that projects are put into individual subdirectories, and in that case the changed behavior does make sense to avoid one level of intermediate directories.

Where is this documented?

I am still looking for anything written. However, I noticed that the Visual Studio IDE correctly shows the default value of "Intermediate Directory" to be different for the two projects in the solution file:

Note the addition of $(ShortProjectName). So at least this is consistent.

So one should probably note that MSBuild uses $(ShortProjectName)\$(Platform)\$(Configuration)\ as a default Intermediate Directory for *.sln root projects as well as when compiling individual *.vcxproj files.

Google-searching for ShortProjectName reveals that this additional level of Intermediate Directory is intended and was introduced in VS 2022 17.9, see Issue with Intermediate Directory (new folder when building) since update to VS 2022 CE 17.9.0.

How can I configure this to stay constant?

Given the previous answer, the solution is straightforward: by overwriting the default value of Intermediate Directory, e.g., in each vcxproj file or, somewhat more elegantly, using a shared property or even a Directory.build.props file:

<?xml version = "1.0" encoding="utf-8"?>
<Project ToolsVersion = "4.0" xmlns="http://schemas.microsoft/developer/msbuild/2003">
  <PropertyGroup>
    <!-- https://stackoverflow/q/79199847/ -->
    <IntDir>$(Platform)\$(Configuration)\</IntDir>
  </PropertyGroup>
</Project>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745619455a4636434.html

相关推荐

  • 国产之光!!让你的Docker管理更优雅!

    大家好,我是热爱开源的了不起!我们都知道,Docker是个好东西,能帮我们把应用打包成容器,方便部署和管理。但问题来了,Docker的命令行操作对新手来说有点复杂,一不小心就容易出错。而且,有时候我们只是想简单地管理一下容器,却得记住一堆命

    1小时前
    00
  • 国产车载通信测试方案:车规级CAN SIC芯片测试技术解析

    随着智能网联汽车的快速发展,车辆内部电子控制单元(ECU)数量激增,动力总成、高级驾驶辅助系统(ADAS)、车身控制等功能对车载通信网络的稳定性与速率提出了更高要求。传统CAN FD总线在复杂拓扑中面临信号振铃、通信速率受限(实际速率通常低

    1小时前
    00
  • OWASP TOP10

    什么是OWASP?它的全称是 Open Web Application Security Project(开放式 Web 应用程序 安全 项目)TOP 10OWASP Top 10的意思就是10项最严重的Web 应用程序安全风险列表 ,它总

    58分钟前
    00
  • 最简 Odoo 部署方法:Websoft9 企业应用托管平台

    传统方式部署 Odoo 通常依赖 Docker 技术,主要分为以下步骤:1 . 安装 Docker需在服务器上安装 Docker 引擎,涉及操作系统兼容性检查、依赖包安装、镜像源配置等操作。代码语言:bash复制 # 以 Ubu

    57分钟前
    00
  • Prometheus配置docker采集器

    Prometheus 配置 Docker 采集器Prometheus 是一个开源的监控系统和时间序列数据库,广泛用于容器化环境中。通过监控 Docker 容器,用户可以实时获取服务性能、资源使用情况等信息。本文将介绍如何为 Docker 容

    55分钟前
    00
  • Go 语言 Mock 实践

    Mock 是软件测试中的一项关键技术,尤其在单元测试领域,可谓是“顶梁柱”般的存在,几乎不可或缺。它通过模拟真实对象的行为,使我们能在不依赖外部系统的情况下,专注测试代码的核心逻辑。对于测试开发、自动化测试,乃至性能测试中的某些场景,合理使

    49分钟前
    00
  • MongoDB “升级项目” 大型连续剧(2)

    上期写的是非必要不升级,想到这个事情,有一些事情的仔细琢磨琢磨,为什么数据库升级的事情在很多公司都是一个困扰,从一个技术人的观点,升级是一件好事,功能提升了,性能提升了,开发效率和一些数据库使用的痛点也被解决了,为什么就不愿意升级呢?如果只

    45分钟前
    00
  • CUT&amp;amp;Tag 数据处理和分析教程(7)

    过滤某些项目可能需要对比对质量分数进行更严格的过滤。本文细讨论了bowtie如何分配质量分数,并举例说明。MAPQ(x) = -10 * log10log10(P(x is mapped wrongly)) = -10 * log10(p)

    44分钟前
    10
  • 什么是docker?它是如何工作的?

    想象一个场景,你要部署一个服务,然后它对环境有很多依赖,不同的操作系统又是不同的需求,而且还可能遇到有些源不能使用,又得一番折腾,折腾完上线后,假设要在新的环境再来一套,又得再来一遍。那么有没有什么办法可以解决呢?有办法,docker就是干

    41分钟前
    00
  • 推荐一个轻量级的监控平台并且支持移动端

    简介XUGOU 是基于Cloudflare构建的轻量化监控平台,专精于系统资源监控与可视化状态页面服务。该平台提供英文简体中文双语支持,满足全球化部署需求。面向开发者及中小团队,项目致力于提供高可用性的监控解决方案。核心功能与实现平台功能

    38分钟前
    00
  • module &#x27;torch.

    踩坑Ascend, 安装 pytorch 2.5.1 和 pytorch_npu 2.5.1, import torch 报错.执行 python -c "import torch;import torch_npu;"时

    36分钟前
    10
  • 大模型驱动金融数据应用的实战探索

    近年来,人工智能技术的飞速发展正在重塑全球各行各业的生态格局,金融行业作为数据密集型领域,更是首当其冲。大模型凭借其强大的自然语言处理、逻辑推理和生成能力,逐渐成为金融数据应用的核心驱动力。本文将从行业背景与趋势、核心场景重构、产品能力提升

    33分钟前
    00
  • maxwell遇到的一则问题

    结论和原因maxwell的元数据库里面没有存储全部的schema数据(就是少数据了),导致相关表的DDL校验失败。PS:我这里maxwell的作用只是采集库表修改情况的统计粗粒度指标,因为之前maxwell在运行报错的时候,直接修改了pos

    30分钟前
    00
  • Nat. Mater.

    大家好,今天给大家分享一篇近期发表在Nat. Mater.上的研究进展,题为:De novo design of self-assembling peptides with antimicrobial activity guided

    25分钟前
    00
  • 雨晨 22635.5170 Windows 11 企业版 23H2 轻装版

    文件: 雨晨 22635.5170 Windows 11 企业版 23H2 轻装版 install.esd 大小: 2920270404 字节 修改时间: 2025年4月8日, 星期二, 11 : 04 : 59 MD5: D5F8F0AD

    23分钟前
    00
  • 子网掩码是怎么“掩”的?用积木教你彻底搞懂!

    子网掩码是怎么“掩”的?用积木教你彻底搞懂!前言肝文不易,点个免费的赞和关注,有错误的地方请指出,看个人主页有惊喜。作者:神的孩子都在歌唱你是不是也曾被“子网掩码”这个术语搞得晕头转向?明明是学网络的第一步,却像是打开了数学世界的大门:2

    20分钟前
    00
  • 1.54G 雨晨 26100.3775 Windows 11 IoT 企业版 LTSC 24H2 极速版

    精简AERO外主题并增加一套壁纸主题&#xff08;默认启用&#xff09;误杀导致功能界面空白、因WMIC被默认移除系统可能会多次重启。 拒止连接 www.5909 拒止连接 www.mnpc 拒止连接 quark 拒止

    20分钟前
    00
  • 用Xshell8配置密钥登陆

    1.首先在服务端查看root.sshauthorized_keys是否存在,这是存储公钥的文件,若不存在需新建此文件 2. 打开Xshell8,选择"新建",选择"新建用户密钥生成向导" 给用户

    14分钟前
    00
  • 设计模式:工厂方法模式(Factory Method)(2)

    当年做一个项目时,还不懂什么是设计模式,仅仅是按照经验完成了需求。回头看看,就是暗合桥接模式。但是,在整个需求实现过程中,甲方需要我在已经设计好的标准业务逻辑中添加非标的需求,因为,在他们眼里,从业务角度来看,是自然的拓展。如果当年我知道还

    9分钟前
    00
  • 电子产品设计与电源优化实用策略

    产品降成本是商业活动中的常见行为,可贯穿于产品设计、研发、生产、运输、销售及维护的各个环节。然而,降成本策略必须建立在对产品品质要求不降低的基础上,确保设计参数满足要求并通过相关测试。以下是具体优化与深度分析。研发工程师通常从设计入手,选择

    6分钟前
    00

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信