I am trying to setup a default location for OutDir
and IntDir
to be used by all projects in the solution. Such as: <OutDir>$(SolutionDir)bld$(Platform)$(ProjectName)$(Configuration)</OutDir>
When I set this in the Directory.Build.props
file, it looks okay in Visual Studio Properties dialog; but when I build, the $(ProjectName)
portion is empty. This tells me that this macro was not available when OutDir was read in Directory.Build.props.
I tried adding this to the Directory.Build.targets
file and it appeared to be ignored altogether.
Another goal is to not modify any of the vcxproj files after this initial change. And new projects would inherit these settings automatically.
Is this possible? Perhaps I am placing the setting in the wrong place/order in the file... ?
This is a snippet of the Directory.Build.props:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets">
</ImportGroup>
<!-- Define macros for easy and consistent access to various parts of the tree -->
<PropertyGroup Label="UserMacros">
<GslInclude>$(SolutionDir)packagesMicrosoft.Gsl.0.1.2.1uild
ativeinclude</GslInclude>
<mySrcDir>$(SolutionDir)src</mySrcDir>
<myBldDir>$(SolutionDir)bld</myBldDir>
<myBldIntDir>$(SolutionDir)bld_int</myBldIntDir>
</PropertyGroup>
<ItemDefinitionGroup />
<ItemGroup>
<BuildMacro Include="GslInclude"> <Value>$(GslInclude)</Value> </BuildMacro>
<BuildMacro Include="mySrcDir"> <Value>$(mySrcDir)</Value> </BuildMacro>
<BuildMacro Include="myBldDir"> <Value>$(myBldDir)</Value> </BuildMacro>
<BuildMacro Include="myBldIntDir"> <Value>$(myBldIntDir)</Value> </BuildMacro>
</ItemGroup>
<!-- Platform Toolset, Windows SDK -->
<PropertyGroup Label="Globals">
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<!-- Default Compiler settings -->
<ItemDefinitionGroup>
<ClCompile>
<!-- .... -->
</ClCompile>
</ItemDefinitionGroup>
<!-- Default Folders for target output -->
<PropertyGroup>
<OutDir>$(myBldDir)$(Platform)$(ProjectName)$(Configuration)</OutDir>
<IntDir>$(myBldIntDir)$(Platform)$(ProjectName)$(Configuration)</IntDir>
</PropertyGroup>
</Project>
And then of course, I simply remove all <OutDir>
and <IntDir>
settings in the proj files.
I would also love to be able to place conditions on settings based on the version of Visual Studio. Some of our developers are using VS2017 with older ToolSet; some are using VS2019 with the latest....
question from:
https://stackoverflow.com/questions/66068782/setting-outdir-and-intdir-for-all-projects 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…