diff --git a/MSBuild.sln b/MSBuild.sln index 105c979813e..966817afd12 100644 --- a/MSBuild.sln +++ b/MSBuild.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27004.2009 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30320.27 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4900B3B8-4310-4D5B-B1F7-2FDF9199765F}" ProjectSection(SolutionItems) = preProject @@ -65,6 +65,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSBuild.Engine.Corext", "sr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSBuild.Bootstrap", "src\MSBuild.Bootstrap\MSBuild.Bootstrap.csproj", "{CEAEE4FE-9298-443B-AFC5-0F72472484B6}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.UnGAC", "src\Package\Microsoft.Build.UnGAC\Microsoft.Build.UnGAC.csproj", "{B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -834,6 +836,36 @@ Global {CEAEE4FE-9298-443B-AFC5-0F72472484B6}.Release-MONO|x64.Build.0 = Release-MONO|x64 {CEAEE4FE-9298-443B-AFC5-0F72472484B6}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU {CEAEE4FE-9298-443B-AFC5-0F72472484B6}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug|x64.ActiveCfg = Debug|x64 + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug|x64.Build.0 = Debug|x64 + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug|x86.ActiveCfg = Debug|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug|x86.Build.0 = Debug|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug-MONO|x64.ActiveCfg = Debug-MONO|x64 + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug-MONO|x64.Build.0 = Debug-MONO|x64 + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.MachineIndependent|x64.ActiveCfg = MachineIndependent|x64 + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.MachineIndependent|x64.Build.0 = MachineIndependent|x64 + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release|Any CPU.Build.0 = Release|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release|x64.ActiveCfg = Release|x64 + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release|x64.Build.0 = Release|x64 + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release|x86.ActiveCfg = Release|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release|x86.Build.0 = Release|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release-MONO|x64.ActiveCfg = Release-MONO|x64 + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release-MONO|x64.Build.0 = Release-MONO|x64 + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -850,6 +882,7 @@ Global {16DBDF17-3E0E-4140-989A-B42638126A40} = {9BAD9352-DEFB-45E5-B8A4-4816B9B22A33} {EDBFE32E-F264-4F01-97C3-B58F8B9165C9} = {9BAD9352-DEFB-45E5-B8A4-4816B9B22A33} {3D67E4FF-6EC6-4FE7-82F1-0DACE1E399A7} = {9BAD9352-DEFB-45E5-B8A4-4816B9B22A33} + {B60173F0-F9F0-4688-9DF8-9ADDD57BD45F} = {9BAD9352-DEFB-45E5-B8A4-4816B9B22A33} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F948D667-14E3-4F98-BA50-3F3C948BF4C2} diff --git a/eng/Signing.props b/eng/Signing.props index 13912cb79a5..b07f715e5ab 100644 --- a/eng/Signing.props +++ b/eng/Signing.props @@ -2,7 +2,7 @@ - - + + \ No newline at end of file diff --git a/src/Package/MSBuild.VSSetup/files.swr b/src/Package/MSBuild.VSSetup/files.swr index d813b8deb3d..8449a0b7149 100644 --- a/src/Package/MSBuild.VSSetup/files.swr +++ b/src/Package/MSBuild.VSSetup/files.swr @@ -6,6 +6,7 @@ package name=Microsoft.Build vs.package.language=neutral vs.dependencies + vs.dependency id=Microsoft.Build.UnGAC vs.dependency id=Microsoft.VisualStudio.PackageGroup.NuGet version=[15.0,17.0) diff --git a/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj b/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj new file mode 100644 index 00000000000..6282c3a2134 --- /dev/null +++ b/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj @@ -0,0 +1,29 @@ + + + + net45 + + Exe + + Microsoft.Build.UnGAC.exe + + Microsoft.Build.UnGAC + + + + <_SwixArgs Include="PackageType=manifest"/> + + <_SwixArgs Include="TargetExt=.json"/> + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs b/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs new file mode 100644 index 00000000000..f468942cf12 --- /dev/null +++ b/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.Build.UnGAC +{ + // See: https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-api/fusion/iassemblycache-interface + [ComImport, Guid("E707DCDE-D1CD-11D2-BAB9-00C04F8ECEAE"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IAssemblyCache + { + [PreserveSig] + uint UninstallAssembly(uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pszAssemblyName, IntPtr pRefData, ref ulong pulDisposition); + } + + public static class NativeMethods + { + [DllImport("fusion.dll")] + internal static extern uint CreateAssemblyCache(out IAssemblyCache ppAsmCache, int dwReserved); + } +} diff --git a/src/Package/Microsoft.Build.UnGAC/Program.cs b/src/Package/Microsoft.Build.UnGAC/Program.cs new file mode 100644 index 00000000000..c5b5caa710d --- /dev/null +++ b/src/Package/Microsoft.Build.UnGAC/Program.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +namespace Microsoft.Build.UnGAC +{ + /// + /// Original Issue: https://github.com/dotnet/msbuild/issues/5183 + /// This tool was created to help prevent customers from putting MSBuild assemblies in the Global Assembly Cache. + /// It runs at VS install-time as well as repair-time. + /// It is intended to run as best effort. Meaning that if it fails, we avoid throwing and instead log it. + /// + class Program + { + static void Main(string[] args) + { + try + { + string[] assembliesToUnGAC = + { + "Microsoft.Build, Version=15.1.0.0", + "Microsoft.Build.Engine, Version=15.1.0.0", + "Microsoft.Build.Framework, Version=15.1.0.0", + "Microsoft.Build.Tasks.Core, Version=15.1.0.0", + "Microsoft.Build.Utilities.Core, Version=15.1.0.0", + "Microsoft.Build.Conversion.Core, Version=15.1.0.0" + }; + + uint hresult = NativeMethods.CreateAssemblyCache(out IAssemblyCache assemblyCache, 0); + + // Most significant bit is set, meaning there was an error in the Hresult. + if ((hresult >> 31) == 1) + { + Console.WriteLine($"Could not successfully call CreateAssemblyCache. HResult: {hresult}"); + Console.WriteLine("Exiting without removing assemblies from the GAC..."); + return; + } + + foreach (string assembly in assembliesToUnGAC) + { + hresult = assemblyCache.UninstallAssembly(dwFlags: 0, pszAssemblyName: assembly, pRefData: IntPtr.Zero, pulDisposition: 0); + + Console.WriteLine($"Tried to remove {assembly} from the GAC. HResult: 0x{hresult:X8}"); + } + } + catch (Exception e) + { + Console.WriteLine($"Caught an exception! We don't want to throw because we want MSBuild to install.\n" + e.ToString()); + } + } + } +} diff --git a/src/Package/Microsoft.Build.UnGAC/exe.swr b/src/Package/Microsoft.Build.UnGAC/exe.swr new file mode 100644 index 00000000000..9a717021a50 --- /dev/null +++ b/src/Package/Microsoft.Build.UnGAC/exe.swr @@ -0,0 +1,19 @@ +use vs + +package name=Microsoft.Build.UnGAC + version=$(Version) + vs.package.type=exe + vs.package.chip=neutral + vs.package.language=neutral + +vs.installCommand fileName=[Payload] + +vs.repairCommand fileName=[Payload] + +vs.installSize + SystemDrive=0 + TargetDrive=0 + SharedDrive=0 + +vs.payloads + vs.payload source=$(BinDir)Microsoft.Build.UnGAC.exe