From 2f335b00e557d5621969bad53f9bc1af387f00a1 Mon Sep 17 00:00:00 2001 From: Nirmal Guru Date: Fri, 3 Apr 2020 22:00:10 +0530 Subject: [PATCH 1/7] Add BaseOutputPath to common targets While this is not officially supported on non-sdk projects, NuGet Pack targets need a common output path to put '.nupkg' across both type of projects --- .../Microsoft.Common.CurrentVersion.targets | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/src/Tasks/Microsoft.Common.CurrentVersion.targets b/src/Tasks/Microsoft.Common.CurrentVersion.targets index a006a2f3083..08670d74d9f 100644 --- a/src/Tasks/Microsoft.Common.CurrentVersion.targets +++ b/src/Tasks/Microsoft.Common.CurrentVersion.targets @@ -68,6 +68,8 @@ Copyright (C) Microsoft Corporation. All rights reserved. + + true true @@ -109,7 +111,15 @@ Copyright (C) Microsoft Corporation. All rights reserved. OutDir can be used to gather multiple project outputs in one location. In addition, OutDir is included in AssemblySearchPaths used for resolving references. + BaseOutputPath: + This is the top level folder where all configuration specific output folders will be created. + Default value is bin\ + OutputPath: + This is the full Output Path, and is derived from BaseOutputPath, if none specified + (eg. bin\Debug). If this property is overridden, then setting BaseOutputPath has no effect. + + For projects loaded with MPFProj (Legacy project system): This property is usually specified in the project file and is used to initialize OutDir. OutDir and OutputPath are distinguished for legacy reasons, and OutDir should be used if at all possible. @@ -119,26 +129,37 @@ Copyright (C) Microsoft Corporation. All rights reserved. IntermediateOutputPath: This is the full intermediate Output Path, and is derived from BaseIntermediateOutputPath, if none specified - (eg. obj\debug). If this property is overridden, then setting BaseIntermediateOutputPath has no effect. + (eg. obj\Debug). If this property is overridden, then setting BaseIntermediateOutputPath has no effect. + + Ensure any and all path property has a trailing slash, so it can be concatenated. --> - true - - $(OutputPath)\ - $(MSBuildProjectName) - - bin\Debug\ - <_OriginalConfiguration>$(Configuration) + <_OriginalPlatform>$(Platform) - Debug - $(Configuration) + AnyCPU + $(Platform) - AnyCPU + <_OriginalConfiguration>$(Configuration) + Debug + $(Configuration) + + bin\ + $(BaseOutputPath)\ + $(BaseOutputPath)$(Configuration)\ + $(BaseOutputPath)$(PlatformName)\$(Configuration)\ + $(OutputPath)\ + obj\ + $(BaseIntermediateOutputPath)\ + $(BaseIntermediateOutputPath)$(Configuration)\ + $(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\ + $(IntermediateOutputPath)\ + + + + + $(TargetType) library exe @@ -201,6 +222,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. $(OutDir)$(ProjectName)\ + $(MSBuildProjectName) $(RootNamespace) $(AssemblyName) @@ -279,26 +301,23 @@ Copyright (C) Microsoft Corporation. All rights reserved. - + $([MSBuild]::Escape($([System.IO.Path]::GetFullPath(`$([System.IO.Path]::Combine(`$(MSBuildProjectDirectory)`, `$(OutDir)`))`)))) - + $(TargetDir)$(TargetFileName) $([MSBuild]::NormalizePath($(TargetDir), 'ref', $(TargetFileName))) - - $(MSBuildProjectDirectory)\ + + $([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)) - + $(ProjectDir)$(ProjectFileName) - - - $(Platform) @@ -336,7 +355,6 @@ Copyright (C) Microsoft Corporation. All rights reserved. false - $(BaseIntermediateOutputPath)\ $(MSBuildProjectFile).FileListAbsolute.txt false @@ -349,12 +367,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. false - - $(BaseIntermediateOutputPath)$(Configuration)\ - $(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\ - - $(IntermediateOutputPath)\ <_GenerateBindingRedirectsIntermediateAppConfig>$(IntermediateOutputPath)$(TargetFileName).config From 1e779a59014c21fe3dadbb99956c437b1e080ccf Mon Sep 17 00:00:00 2001 From: Nirmal Guru Date: Fri, 3 Apr 2020 22:00:13 +0530 Subject: [PATCH 2/7] Use property functions within MSBuild namespace, wherever possible Replace 'HasTrailingSlash' conditional function with '[MSBuild]::EnsureTrailingSlash' property function Replace '[System.IO.Path]::Combine' property function with '[MSBuild]::NormalizePath' and '[MSBuild]::NormalizeDirectory' property functions --- .../Microsoft.Common.CrossTargeting.targets | 2 +- .../Microsoft.Common.CurrentVersion.targets | 28 ++++++++----------- src/Tasks/Microsoft.Common.props | 10 +++---- src/Tasks/Microsoft.Common.targets | 2 +- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/Tasks/Microsoft.Common.CrossTargeting.targets b/src/Tasks/Microsoft.Common.CrossTargeting.targets index 51ef08021b0..c7023d3cca6 100644 --- a/src/Tasks/Microsoft.Common.CrossTargeting.targets +++ b/src/Tasks/Microsoft.Common.CrossTargeting.targets @@ -201,7 +201,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. <_DirectoryBuildTargetsFile Condition="'$(_DirectoryBuildTargetsFile)' == ''">Directory.Build.targets <_DirectoryBuildTargetsBasePath Condition="'$(_DirectoryBuildTargetsBasePath)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), '$(_DirectoryBuildTargetsFile)')) - $([System.IO.Path]::Combine('$(_DirectoryBuildTargetsBasePath)', '$(_DirectoryBuildTargetsFile)')) + $([MSBuild]::NormalizePath('$(_DirectoryBuildTargetsBasePath)', '$(_DirectoryBuildTargetsFile)')) diff --git a/src/Tasks/Microsoft.Common.CurrentVersion.targets b/src/Tasks/Microsoft.Common.CurrentVersion.targets index 08670d74d9f..1522bdfaabb 100644 --- a/src/Tasks/Microsoft.Common.CurrentVersion.targets +++ b/src/Tasks/Microsoft.Common.CurrentVersion.targets @@ -144,17 +144,15 @@ Copyright (C) Microsoft Corporation. All rights reserved. Debug $(Configuration) - bin\ - $(BaseOutputPath)\ + $([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(BaseOutputPath)', 'bin')))) $(BaseOutputPath)$(Configuration)\ $(BaseOutputPath)$(PlatformName)\$(Configuration)\ - $(OutputPath)\ + $([MSBuild]::EnsureTrailingSlash('$(OutputPath)')) - obj\ - $(BaseIntermediateOutputPath)\ + $([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(BaseIntermediateOutputPath)', 'obj')))) $(BaseIntermediateOutputPath)$(Configuration)\ $(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\ - $(IntermediateOutputPath)\ + $([MSBuild]::EnsureTrailingSlash('$(IntermediateOutputPath)')) @@ -212,15 +210,14 @@ Copyright (C) Microsoft Corporation. All rights reserved. true - $(OutputPath) - $(OutDir)\ + $([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(OutDir)', '$(OutputPath)')))) $(MSBuildProjectName) - $(OutDir)$(ProjectName)\ + $([MSBuild]::EnsureTrailingSlash('$(OutDir)$(ProjectName)')) $(MSBuildProjectName) $(RootNamespace) @@ -306,7 +303,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. Condition intentionally omitted on this one, because it causes problems when we pick up the value of an environment variable named TargetDir --> - $([MSBuild]::Escape($([System.IO.Path]::GetFullPath(`$([System.IO.Path]::Combine(`$(MSBuildProjectDirectory)`, `$(OutDir)`))`)))) + $([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', '$(OutDir)')) $(TargetDir)$(TargetFileName) @@ -390,12 +387,12 @@ Copyright (C) Microsoft Corporation. All rights reserved. $(IntermediateOutputPath)$(TargetName).pdb - <_WinMDDebugSymbolsOutputPath>$([System.IO.Path]::Combine('$(OutDir)', $([System.IO.Path]::GetFileName('$(WinMDExpOutputPdb)')))) + <_WinMDDebugSymbolsOutputPath>$(OutDir)$([System.IO.Path]::GetFileName('$(WinMDExpOutputPdb)')) $(IntermediateOutputPath)$(TargetName).xml - <_WinMDDocFileOutputPath>$([System.IO.Path]::Combine('$(OutDir)', $([System.IO.Path]::GetFileName('$(WinMDOutputDocumentationFile)')))) + <_WinMDDocFileOutputPath>$(OutDir)$([System.IO.Path]::GetFileName('$(WinMDOutputDocumentationFile)')) @@ -467,8 +464,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. - $(PublishDir)\ - $(OutputPath)app.publish\ + $([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(PublishDir)', '$(OutputPath)app.publish')))) true - $([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)')) + $(IntermediateOutputPath)$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension) @@ -4581,7 +4577,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. - + diff --git a/src/Tasks/Microsoft.Common.props b/src/Tasks/Microsoft.Common.props index 89e402b0582..942daa68814 100644 --- a/src/Tasks/Microsoft.Common.props +++ b/src/Tasks/Microsoft.Common.props @@ -26,7 +26,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. <_DirectoryBuildPropsFile Condition="'$(_DirectoryBuildPropsFile)' == ''">Directory.Build.props <_DirectoryBuildPropsBasePath Condition="'$(_DirectoryBuildPropsBasePath)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), '$(_DirectoryBuildPropsFile)')) - $([System.IO.Path]::Combine('$(_DirectoryBuildPropsBasePath)', '$(_DirectoryBuildPropsFile)')) + $([MSBuild]::NormalizePath('$(_DirectoryBuildPropsBasePath)', '$(_DirectoryBuildPropsFile)')) @@ -43,18 +43,16 @@ Copyright (C) Microsoft Corporation. All rights reserved. The declaration of $(BaseIntermediateOutputPath) had to be moved up from Microsoft.Common.CurrentVersion.targets in order for the $(MSBuildProjectExtensionsPath) to use it as a default. --> - obj\ - $(BaseIntermediateOutputPath)\ + $([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(BaseIntermediateOutputPath)', 'obj')))) <_InitialBaseIntermediateOutputPath>$(BaseIntermediateOutputPath) - $(BaseIntermediateOutputPath) + $([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(MSBuildProjectExtensionsPath)', '$(BaseIntermediateOutputPath)')))) - $([System.IO.Path]::Combine('$(MSBuildProjectDirectory)', '$(MSBuildProjectExtensionsPath)')) - $(MSBuildProjectExtensionsPath)\ + $([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', '$(MSBuildProjectExtensionsPath)')) true <_InitialMSBuildProjectExtensionsPath Condition=" '$(ImportProjectExtensionProps)' == 'true' ">$(MSBuildProjectExtensionsPath) diff --git a/src/Tasks/Microsoft.Common.targets b/src/Tasks/Microsoft.Common.targets index d88e7eb9221..b3e9be1fa09 100644 --- a/src/Tasks/Microsoft.Common.targets +++ b/src/Tasks/Microsoft.Common.targets @@ -137,7 +137,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. <_DirectoryBuildTargetsFile Condition="'$(_DirectoryBuildTargetsFile)' == ''">Directory.Build.targets <_DirectoryBuildTargetsBasePath Condition="'$(_DirectoryBuildTargetsBasePath)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), '$(_DirectoryBuildTargetsFile)')) - $([System.IO.Path]::Combine('$(_DirectoryBuildTargetsBasePath)', '$(_DirectoryBuildTargetsFile)')) + $([MSBuild]::NormalizePath('$(_DirectoryBuildTargetsBasePath)', '$(_DirectoryBuildTargetsFile)')) From 9a7012e744ae376cb278f10c90eef7d42dba4971 Mon Sep 17 00:00:00 2001 From: Nirmal Guru Date: Fri, 8 May 2020 14:12:16 +0530 Subject: [PATCH 3/7] Fallback to legacy behavior for Configuration/Platform validation when using OutputPath without BaseOutputPath --- .../Microsoft.Common.CurrentVersion.targets | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Tasks/Microsoft.Common.CurrentVersion.targets b/src/Tasks/Microsoft.Common.CurrentVersion.targets index 1522bdfaabb..4d1c2f5ad11 100644 --- a/src/Tasks/Microsoft.Common.CurrentVersion.targets +++ b/src/Tasks/Microsoft.Common.CurrentVersion.targets @@ -137,10 +137,17 @@ Copyright (C) Microsoft Corporation. All rights reserved. <_OriginalPlatform>$(Platform) - AnyCPU - $(Platform) <_OriginalConfiguration>$(Configuration) + + <_OutputPathWasMissing Condition="'$(_OriginalPlatform)' != '' and '$(_OriginalConfiguration)' != '' and '$(OutputPath)' == ''">true + + true + + + + AnyCPU + $(Platform) Debug $(Configuration) @@ -181,12 +188,19 @@ Copyright (C) Microsoft Corporation. All rights reserved. false - + + + When 'OutputPath' is missing or empty (along with non-existent 'BaseOutputPath') at this point means that + we're in legacy mode and we should assume the current Configuration/Platform combination as invalid. + Whether this is considered an error or a warning depends on the value of $(SkipInvalidConfigurations). + --> <_InvalidConfigurationError Condition=" '$(SkipInvalidConfigurations)' != 'true' ">true <_InvalidConfigurationWarning Condition=" '$(SkipInvalidConfigurations)' == 'true' ">true @@ -195,7 +209,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. IDE Macros available from both integrated builds and from command line builds. The following properties are 'macros' that are available via IDE for pre and post build steps. - --> + --> .exe .exe @@ -793,7 +807,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. BeforeTargets="$(BuildDependsOn);Build;$(RebuildDependsOn);Rebuild;$(CleanDependsOn);Clean"> - <_InvalidConfigurationMessageText>The OutputPath property is not set for project '$(MSBuildProjectFile)'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='$(_OriginalConfiguration)' Platform='$(_OriginalPlatform)'. + <_InvalidConfigurationMessageText>The BaseOutputPath/OutputPath property is not set for project '$(MSBuildProjectFile)'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='$(_OriginalConfiguration)' Platform='$(_OriginalPlatform)'. <_InvalidConfigurationMessageText Condition="'$(BuildingInsideVisualStudio)' == 'true'">$(_InvalidConfigurationMessageText) This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform. <_InvalidConfigurationMessageText Condition="'$(BuildingInsideVisualStudio)' != 'true'">$(_InvalidConfigurationMessageText) You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. @@ -806,8 +820,10 @@ Copyright (C) Microsoft Corporation. All rights reserved. - + + + <_InvalidConfigurationError Condition=" '$(SkipInvalidConfigurations)' != 'true' ">true From f7e97bd6f3f929440d709bc7474a3a59a2ba4f33 Mon Sep 17 00:00:00 2001 From: Nirmal Guru Date: Wed, 2 Dec 2020 10:05:52 +0530 Subject: [PATCH 7/7] Add a missing bracket Silly ME! There were a lot of build errors from the Fakes targets. I was banging my head on which change caused this but finally found it. Guess being sick has its perks. --- src/Tasks/Microsoft.Common.CurrentVersion.targets | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Tasks/Microsoft.Common.CurrentVersion.targets b/src/Tasks/Microsoft.Common.CurrentVersion.targets index da26d36c313..c7c94603ad1 100644 --- a/src/Tasks/Microsoft.Common.CurrentVersion.targets +++ b/src/Tasks/Microsoft.Common.CurrentVersion.targets @@ -326,7 +326,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. $([MSBuild]::NormalizePath($(TargetDir), 'ref', $(TargetFileName))) - $([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)) + $([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory))) $(ProjectDir)$(ProjectFileName) @@ -1718,7 +1718,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. - + @(_TargetFrameworkInfo->'%(TargetPlatformMonikers)') true - + false true @@ -4029,7 +4029,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. Name="_DeploymentGenerateLauncher" Condition="'$(GenerateClickOnceManifests)'=='true' and '$(_DeploymentLauncherBased)' == 'true'"> -