From f364187b8dc272de1e291d516216b2e7731f668f Mon Sep 17 00:00:00 2001 From: fourpastmidnight Date: Thu, 13 Aug 2020 18:00:41 -0400 Subject: [PATCH] Fixes OctoPack packages including extra files Back in January, 2018, PR 2878 at dotnet/msbuild was merged. (See https://www.github.com/dotnet/msbuild/pull/2878). There was one simple change, but it unknowingly caused OctoPack to start including extra unnecessary files into OctoPack packages. We found it because we had deployments blow up in Octopus Deploy due to file paths which exceeded MAX_PATH length during deployment, specifically, during config file transformation. The PR had the result of, when copying files marked as CopyLocal, a *.csproj.CopyComplete file is created. It's a marker for the build process so that transitively referenced projects are built appropriately. Near as far as I can tell, because the file is created (via the Touch task) during this target, and subsequently added to the @(FileWrites) item group, and because the path associated with @(CopyUpToDateMarker) item group is an absolute path, the existing exclusion in the OctoPack.targets file is not filtering out these files. So they are being included in the OctoPack deployment packages. While the files are 0-bytes in size and are harmless, they don't belong in the package. They are not a deployable build artifact, and in my case, caused deployment failures. This wasn't caught in changes to OctoPack between Jan. 2018 and Jan. 2019 (the last time any change was made to this repo, and the date of the most recent release) because the unit tests were never appropriately updated to take into account newer versions of Visual Studio, namely Visual Studio 2017 and Visual Studio 2019. This commit updates the unit tests and the OctoPack.targets file so that these useless *.csproj.CopyComplete files are not added to OctoPack deployment packages. --- .../Integration/BuildFixture.cs | 19 ++++++++++++++----- .../Integration/SampleSolutionBuildFixture.cs | 4 ++-- source/build/OctoPack.targets | 10 +++++----- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/source/OctoPack.Tests/Integration/BuildFixture.cs b/source/OctoPack.Tests/Integration/BuildFixture.cs index f2f9729..e30be68 100644 --- a/source/OctoPack.Tests/Integration/BuildFixture.cs +++ b/source/OctoPack.Tests/Integration/BuildFixture.cs @@ -56,13 +56,22 @@ protected static void MsBuild(string commandLineArguments, Action output private static string GetMsBuildPath() { string msBuild; + var programFilesDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); - foreach (var version in new []{"14.0","12.0"}) + foreach (var version in new[] { "Current", "15.0", "14.0", "12.0" }) { - var buildDirectory = Path.Combine(programFilesDirectory, "MSBuild", version, "Bin"); - msBuild = Path.Combine(buildDirectory, "msbuild.exe"); - if (File.Exists(msBuild)) - return msBuild; + // As of Visual Studio 2017, Microsoft changed where the MSBuild tools reside. As of Visual Studio 2019, Microsoft stopped using + // a version number, such as 15.0, in the path and now uses 'Current'. + // This additional loop accounts for MSBuild located in the Visual Studio installation path for both VS2017 and VS2019 Professional + // and enterprise editions. This is still fragile, as there are other editions of Visual Studio, and also does not account for + // the Visual Studio Build Tools (for 2017 and 2019). + // The last empty string array entry is for Visual Studio 2015 and below. + foreach (var msBuildBasePath in new[] { "Microsoft Visual Studio\\2019\\Professional", "Microsoft Visual Studio\\2019\\Enterprise", "Microsoft Visual Studio\\2017\\Professional", "Microsoft Visual Studio\\2017\\Enterprise", "" }) + { + msBuild = Path.Combine(programFilesDirectory, msBuildBasePath, "MSBuild", version, "Bin", "msbuild.exe"); + if (File.Exists(msBuild)) + return msBuild; + } } var netFx = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(); msBuild = Path.Combine(netFx, "msbuild.exe"); diff --git a/source/OctoPack.Tests/Integration/SampleSolutionBuildFixture.cs b/source/OctoPack.Tests/Integration/SampleSolutionBuildFixture.cs index 8a64920..302a78e 100644 --- a/source/OctoPack.Tests/Integration/SampleSolutionBuildFixture.cs +++ b/source/OctoPack.Tests/Integration/SampleSolutionBuildFixture.cs @@ -5,7 +5,7 @@ namespace OctoPack.Tests.Integration { - [TestFixture] + [TestFixture, Category("Integration Tests")] public class SampleSolutionBuildFixture : BuildFixture { [Test] @@ -13,7 +13,7 @@ public void ShouldBuildAtSolutionLevel() { MsBuild("Samples.sln /p:RunOctoPack=true /p:OctoPackPackageVersion=1.0.9 /p:Configuration=Release /v:m"); - AssertPackage(@"Sample.ConsoleApp\obj\octopacked\Sample.ConsoleApp.1.0.9.nupkg", + AssertPackage(@"Sample.ConsoleApp\obj\octopacked\Sample.ConsoleApp.1.0.9.nupkg", pkg => pkg.AssertContents( "Sample.ConsoleApp.exe", "Sample.ConsoleApp.exe.config", diff --git a/source/build/OctoPack.targets b/source/build/OctoPack.targets index 8e90f58..c7c6906 100644 --- a/source/build/OctoPack.targets +++ b/source/build/OctoPack.targets @@ -9,7 +9,7 @@ OctoPack - + @@ -40,7 +40,7 @@ false - @@ -67,13 +67,13 @@ - + - + - +