当在特定场景中只请求Release时,为什么msbuild同时在Debug和Release中编译



我正在Release配置中构建两个解决方案。然而,第二个解决方案在Debug中重建了一些项目!

我能够将测试用例减少到最低限度。它包含4个文件-2个sln和2个csproj文件。

它们在这里:

DataSv.sln


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2048
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "CommonCommon.csproj", "{04455D86-A7A4-41E5-B3ED-B0BC65EAFDFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compensation.Data", "Compensation.DataCompensation.Data.csproj", "{04DF77A2-912B-40B7-B398-E9558519CAEE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{04455D86-A7A4-41E5-B3ED-B0BC65EAFDFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04455D86-A7A4-41E5-B3ED-B0BC65EAFDFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04455D86-A7A4-41E5-B3ED-B0BC65EAFDFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04455D86-A7A4-41E5-B3ED-B0BC65EAFDFD}.Release|Any CPU.Build.0 = Release|Any CPU
{04DF77A2-912B-40B7-B398-E9558519CAEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04DF77A2-912B-40B7-B398-E9558519CAEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04DF77A2-912B-40B7-B398-E9558519CAEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04DF77A2-912B-40B7-B398-E9558519CAEE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9ED7ECEC-075D-486A-B3F6-9E80EED49AEF}
EndGlobalSection
EndGlobal

Main.sln

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compensation.Data", "Compensation.DataCompensation.Data.csproj", "{04DF77A2-912B-40B7-B398-E9558519CAEE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{04DF77A2-912B-40B7-B398-E9558519CAEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04DF77A2-912B-40B7-B398-E9558519CAEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04DF77A2-912B-40B7-B398-E9558519CAEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04DF77A2-912B-40B7-B398-E9558519CAEE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6FBE2C7C-DCEA-4F88-BF8E-FF4927DEFBE5}
EndGlobalSection
EndGlobal

Common\csproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)Microsoft.Common.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{04455D86-A7A4-41E5-B3ED-B0BC65EAFDFD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Xyz.Common</RootNamespace>
<AssemblyName>Xyz.Common</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<OutputPath>Bin$(Configuration)</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)Microsoft.CSharp.targets" />
</Project>

补偿数据.csproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{04DF77A2-912B-40B7-B398-E9558519CAEE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Compensation.Data</RootNamespace>
<AssemblyName>Compensation.Data</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<OutputPath>Bin$(Configuration)</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..CommonCommon.csproj">
<Project>{04455d86-a7a4-41e5-b3ed-b0bc65eafdfd}</Project>
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)Microsoft.CSharp.targets" />
</Project>

需要注意的事项:

  1. Compensation.Data项目同时加载在DataSvc.sln和Main.sln中
  2. Compensation.Data项目引用Common项目作为项目,而不是DLL,即使在Main.sln中找不到它

问题-在Release中编译两个解决方案时,Main.sln在Debug构建Common

请注意:

C:workMSBuildBug [master]> git clean -qdfX
C:workMSBuildBug [master]> Test-Path .CommonbinDebug
False
C:workMSBuildBug [master]> msbuild .DataSvc.sln /v:m /nowarn:CS2008 /nologo /p:Configuration=Release
Common -> C:workMSBuildBugCommonBinReleaseXyz.Common.dll
Compensation.Data -> C:workMSBuildBugCompensation.DataBinReleaseCompensation.Data.dll
C:workMSBuildBug [master]> Test-Path .CommonbinDebug
False
C:workMSBuildBug [master]> msbuild .Main.sln /v:m /nowarn:CS2008 /nologo /p:Configuration=Release
Common -> C:workMSBuildBugCommonBinDebugXyz.Common.dll
Compensation.Data -> C:workMSBuildBugCompensation.DataBinReleaseCompensation.Data.dll
C:workMSBuildBug [master]> Test-Path .CommonbinDebug
True
C:workMSBuildBug [master]> dir .CommonbinDebug

Directory: C:workMSBuildBugCommonbinDebug

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2/18/2020   1:24 AM           3584 Xyz.Common.dll
-a----        2/18/2020   1:24 AM           7680 Xyz.Common.pdb

C:workMSBuildBug [master]>

这在VS 2017和VS 2019中都是如此。

我在这里错过了什么?为什么它在Debug中编译?

答案在这里-https://github.com/microsoft/msbuild/issues/5116#issuecomment-584211463

设置此项(例如在Directory.Build.props中(可以解决问题:

<ShouldUnsetParentConfigurationAndPlatform>false</ShouldUnsetParentConfigurationAndPlatform>