From 3b39127fa396e34b6f63800ad37942926e91f360 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Wed, 29 Jul 2020 17:10:49 -0700 Subject: [PATCH 01/24] First implementation of Microsoft.Build.UnGAC. Workarounds galore! --- MSBuild.Dev.sln | 36 +++++- MSBuild.sln | 36 +++++- src/Microsoft.Build.UnGAC/App.config | 6 + .../Microsoft.Build.UnGAC.csproj | 52 +++++++++ src/Microsoft.Build.UnGAC/Program.cs | 108 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ 6 files changed, 270 insertions(+), 4 deletions(-) create mode 100644 src/Microsoft.Build.UnGAC/App.config create mode 100644 src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj create mode 100644 src/Microsoft.Build.UnGAC/Program.cs create mode 100644 src/Microsoft.Build.UnGAC/Properties/AssemblyInfo.cs diff --git a/MSBuild.Dev.sln b/MSBuild.Dev.sln index 395bc1d6691..253e38476e1 100644 --- a/MSBuild.Dev.sln +++ b/MSBuild.Dev.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 @@ -33,6 +33,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.Utilities.U EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xunit.NetCore.Extensions", "src\Xunit.NetCore.Extensions\Xunit.NetCore.Extensions.csproj", "{66C6C1ED-30E7-45DD-9F73-2FBB7889CDBA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Build.UnGAC", "src\Microsoft.Build.UnGAC\Microsoft.Build.UnGAC.csproj", "{ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -412,6 +414,36 @@ Global {66C6C1ED-30E7-45DD-9F73-2FBB7889CDBA}.Release-MONO|x64.Build.0 = Release|x64 {66C6C1ED-30E7-45DD-9F73-2FBB7889CDBA}.Release-MONO|x86.ActiveCfg = Release|Any CPU {66C6C1ED-30E7-45DD-9F73-2FBB7889CDBA}.Release-MONO|x86.Build.0 = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x64.ActiveCfg = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x64.Build.0 = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x86.ActiveCfg = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x86.Build.0 = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x64.ActiveCfg = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x64.Build.0 = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x64.ActiveCfg = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x64.Build.0 = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|Any CPU.Build.0 = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x64.ActiveCfg = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x64.Build.0 = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x86.ActiveCfg = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x86.Build.0 = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x64.ActiveCfg = Release-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x64.Build.0 = Release-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MSBuild.sln b/MSBuild.sln index 105c979813e..b7ff1908291 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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Build.UnGAC", "src\Microsoft.Build.UnGAC\Microsoft.Build.UnGAC.csproj", "{ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}" +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 + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x64.ActiveCfg = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x64.Build.0 = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x86.ActiveCfg = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x86.Build.0 = Debug|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x64.ActiveCfg = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x64.Build.0 = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x64.ActiveCfg = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x64.Build.0 = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|Any CPU.Build.0 = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x64.ActiveCfg = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x64.Build.0 = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x86.ActiveCfg = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x86.Build.0 = Release|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x64.ActiveCfg = Release-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x64.Build.0 = Release-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Microsoft.Build.UnGAC/App.config b/src/Microsoft.Build.UnGAC/App.config new file mode 100644 index 00000000000..8e15646352e --- /dev/null +++ b/src/Microsoft.Build.UnGAC/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj b/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj new file mode 100644 index 00000000000..e7749a96c0c --- /dev/null +++ b/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621} + Exe + Microsoft.Build.UnGAC + Microsoft.Build.UnGAC + v4.5 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Microsoft.Build.UnGAC/Program.cs b/src/Microsoft.Build.UnGAC/Program.cs new file mode 100644 index 00000000000..3ba0380aa04 --- /dev/null +++ b/src/Microsoft.Build.UnGAC/Program.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.ExceptionServices; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.Build.UnGAC +{ + class Program + { + static void Main(string[] args) + { + char c = ' '; + List allInstancesOfGACUtil = new List(); + StreamReader output; + StreamWriter input; + + Process proc = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "C:\\Windows\\System32\\cmd.exe", + Arguments = "/k", + RedirectStandardOutput = true, + RedirectStandardInput = true, + UseShellExecute = false + } + }; + proc.Start(); + + // hook into standard input/output of the process + output = proc.StandardOutput; + input = proc.StandardInput; + + // use where.exe to find gacutil.exe + input.WriteLine("where /F /R \"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\" gacutil.exe"); + + //throw away the first line - it's the command we just used + output.ReadLine(); + string s = output.ReadLine(); + + // store all instances of gacutil.exe + // doing this for now but not acting on it to acknowledge that some weird scenario may prevent us from using the + // first found gacutil. + while (!String.IsNullOrEmpty(s)) + { + allInstancesOfGACUtil.Add(s); + s = output.ReadLine(); + } + + //couldn't find gacutil, quietly fail. + if (allInstancesOfGACUtil.Count <= 0) + { + proc.Close(); + Console.WriteLine("Could not find instances of gacutil, exiting..."); + return; + } + + // we've found gacutil, now let's use it. + string gacUtilExe = allInstancesOfGACUtil[0]; + + if (proc.StandardInput.BaseStream.CanWrite) + { + input.WriteLine($"{gacUtilExe} /nologo /u \"MSBuild, Version=15.1.0.0\""); + input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build.Conversion.Core, Version=15.1.0.0\""); + input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build, Version=15.1.0.0\""); + input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build.Engine, Version=15.1.0.0\""); + input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build.Tasks.Core, Version=15.1.0.0\""); + input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build.Utilities.Core, Version=15.1.0.0\""); + input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build.Framework, Version=15.1.0.0\""); + + } + + if(output.BaseStream.CanSeek && output.Peek() == -1) + { + + } + //hacky temporary workaround + int i = 0; + + // Peek is a strange beast. It returns a -1 if no character can be read or if the stream does not support seeking. + // Yet there are cases where you can peek a -1, yet read() returns a valid character. + // I've tested breakpoints where output.Peek() == -1 && output.BaseStream.Caneek == true, but it never gets hit. + + while (!(i > 2000 && output.Peek() == -1)) + { + // We're reading because if you happen to attempt a ReadLine() at the end of the stream, it will lock up. + // With reading we can at least preemptively catch it before it locks (hence the hacky temporary workaround). + c = (char)output.Read(); + + Console.Write(c); + i++; + + if (output.BaseStream.CanSeek && output.Peek() == -1) + { + + } + } + + proc.Close(); + proc.Dispose(); + Console.ReadKey(); + } + } +} diff --git a/src/Microsoft.Build.UnGAC/Properties/AssemblyInfo.cs b/src/Microsoft.Build.UnGAC/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..cd5dbc0fd44 --- /dev/null +++ b/src/Microsoft.Build.UnGAC/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Microsoft.Build.UnGAC")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Microsoft.Build.UnGAC")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ed38be62-db5e-4dad-af05-2aa5594b1621")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] From ae20d691be95649fa990fb828cb6159718451ce2 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Wed, 29 Jul 2020 17:11:16 -0700 Subject: [PATCH 02/24] comments --- src/Microsoft.Build.UnGAC/Program.cs | 36 ++++++++++------------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/Microsoft.Build.UnGAC/Program.cs b/src/Microsoft.Build.UnGAC/Program.cs index 3ba0380aa04..822b519c92b 100644 --- a/src/Microsoft.Build.UnGAC/Program.cs +++ b/src/Microsoft.Build.UnGAC/Program.cs @@ -36,22 +36,23 @@ static void Main(string[] args) input = proc.StandardInput; // use where.exe to find gacutil.exe - input.WriteLine("where /F /R \"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\" gacutil.exe"); + if (input.BaseStream.CanWrite) + { + input.WriteLine("where /F /R \"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\" gacutil.exe"); + } //throw away the first line - it's the command we just used output.ReadLine(); string s = output.ReadLine(); // store all instances of gacutil.exe - // doing this for now but not acting on it to acknowledge that some weird scenario may prevent us from using the - // first found gacutil. + // doing this for now "just in case" while (!String.IsNullOrEmpty(s)) { allInstancesOfGACUtil.Add(s); s = output.ReadLine(); } - //couldn't find gacutil, quietly fail. if (allInstancesOfGACUtil.Count <= 0) { proc.Close(); @@ -64,27 +65,21 @@ static void Main(string[] args) if (proc.StandardInput.BaseStream.CanWrite) { - input.WriteLine($"{gacUtilExe} /nologo /u \"MSBuild, Version=15.1.0.0\""); - input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build.Conversion.Core, Version=15.1.0.0\""); - input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build, Version=15.1.0.0\""); - input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build.Engine, Version=15.1.0.0\""); - input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build.Tasks.Core, Version=15.1.0.0\""); - input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build.Utilities.Core, Version=15.1.0.0\""); - input.WriteLine($"{gacUtilExe} /nologo /u \"Microsoft.Build.Framework, Version=15.1.0.0\""); - + input.WriteLine($"{gacUtilExe} /nologo /u \"MSBuild, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Conversion.Core, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Engine, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Tasks.Core, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Utilities.Core, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Framework, Version=15.1.0.0\"\n"); } - if(output.BaseStream.CanSeek && output.Peek() == -1) - { - - } //hacky temporary workaround int i = 0; - // Peek is a strange beast. It returns a -1 if no character can be read or if the stream does not support seeking. + // Peek is a strange beast. It returns a -1 if "no character can be read or if the stream does not support seeking." // Yet there are cases where you can peek a -1, yet read() returns a valid character. // I've tested breakpoints where output.Peek() == -1 && output.BaseStream.Caneek == true, but it never gets hit. - while (!(i > 2000 && output.Peek() == -1)) { // We're reading because if you happen to attempt a ReadLine() at the end of the stream, it will lock up. @@ -93,11 +88,6 @@ static void Main(string[] args) Console.Write(c); i++; - - if (output.BaseStream.CanSeek && output.Peek() == -1) - { - - } } proc.Close(); From cbbd763d8300bd7805a3431ce1fb5db78fc225ea Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Tue, 4 Aug 2020 14:28:08 -0700 Subject: [PATCH 03/24] Added .swr file. Try catching the program to ensure it doesn't fail and thus prevent MSBuild from installing --- src/Microsoft.Build.UnGAC/Program.cs | 141 ++++++++++++++------------ src/Package/MSBuild.VSSetup/exe.swr | 20 ++++ src/Package/MSBuild.VSSetup/files.swr | 1 + 3 files changed, 95 insertions(+), 67 deletions(-) create mode 100644 src/Package/MSBuild.VSSetup/exe.swr diff --git a/src/Microsoft.Build.UnGAC/Program.cs b/src/Microsoft.Build.UnGAC/Program.cs index 822b519c92b..90dddaa2304 100644 --- a/src/Microsoft.Build.UnGAC/Program.cs +++ b/src/Microsoft.Build.UnGAC/Program.cs @@ -13,86 +13,93 @@ class Program { static void Main(string[] args) { - char c = ' '; - List allInstancesOfGACUtil = new List(); - StreamReader output; - StreamWriter input; - - Process proc = new Process + try { - StartInfo = new ProcessStartInfo + List allInstancesOfGACUtil = new List(); + StreamReader output; + StreamWriter input; + + Process proc = new Process { - FileName = "C:\\Windows\\System32\\cmd.exe", - Arguments = "/k", - RedirectStandardOutput = true, - RedirectStandardInput = true, - UseShellExecute = false - } - }; - proc.Start(); + StartInfo = new ProcessStartInfo + { + FileName = "C:\\Windows\\System32\\cmd.exe", + Arguments = "/k", // keep cmd open until we're done + RedirectStandardOutput = true, + RedirectStandardInput = true, + UseShellExecute = false + } + }; + proc.Start(); - // hook into standard input/output of the process - output = proc.StandardOutput; - input = proc.StandardInput; + // hook into standard input/output of the process + output = proc.StandardOutput; + input = proc.StandardInput; - // use where.exe to find gacutil.exe - if (input.BaseStream.CanWrite) - { - input.WriteLine("where /F /R \"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\" gacutil.exe"); - } + // use where.exe to find gacutil.exe + if (input.BaseStream.CanWrite) + { + input.WriteLine("where /F /R \"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\" gacutil.exe"); + } - //throw away the first line - it's the command we just used - output.ReadLine(); - string s = output.ReadLine(); + //throw away the first line - it's the command we just used + output.ReadLine(); + string s = output.ReadLine(); - // store all instances of gacutil.exe - // doing this for now "just in case" - while (!String.IsNullOrEmpty(s)) - { - allInstancesOfGACUtil.Add(s); - s = output.ReadLine(); - } + // store all instances of gacutil.exe + // doing this for now "just in case" + while (!String.IsNullOrEmpty(s)) + { + allInstancesOfGACUtil.Add(s); + s = output.ReadLine(); + } - if (allInstancesOfGACUtil.Count <= 0) - { - proc.Close(); - Console.WriteLine("Could not find instances of gacutil, exiting..."); - return; - } + if (allInstancesOfGACUtil.Count <= 0) + { + proc.Close(); + Console.WriteLine("Could not find instances of gacutil, exiting..."); + return; + } - // we've found gacutil, now let's use it. - string gacUtilExe = allInstancesOfGACUtil[0]; + // we've found gacutil, now let's use it. + string gacUtilExe = allInstancesOfGACUtil[0]; - if (proc.StandardInput.BaseStream.CanWrite) - { - input.WriteLine($"{gacUtilExe} /nologo /u \"MSBuild, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Conversion.Core, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Engine, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Tasks.Core, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Utilities.Core, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Framework, Version=15.1.0.0\"\n"); - } + if (input.BaseStream.CanWrite) + { + input.WriteLine($"{gacUtilExe} /nologo /u \"MSBuild, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Conversion.Core, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Engine, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Tasks.Core, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Utilities.Core, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Framework, Version=15.1.0.0\"\n"); + } - //hacky temporary workaround - int i = 0; + //hacky temporary workaround + int i = 0; - // Peek is a strange beast. It returns a -1 if "no character can be read or if the stream does not support seeking." - // Yet there are cases where you can peek a -1, yet read() returns a valid character. - // I've tested breakpoints where output.Peek() == -1 && output.BaseStream.Caneek == true, but it never gets hit. - while (!(i > 2000 && output.Peek() == -1)) - { - // We're reading because if you happen to attempt a ReadLine() at the end of the stream, it will lock up. - // With reading we can at least preemptively catch it before it locks (hence the hacky temporary workaround). - c = (char)output.Read(); + // Peek is a strange beast. It returns a -1 if "no character can be read or if the stream does not support seeking." + // Yet there are cases where you can peek a -1 and read() returns a valid character. + // I've tested breakpoints where output.Peek() == -1 && output.BaseStream.CanSeek == true, but it never gets hit. + while (!(i > 2000 && output.Peek() == -1)) + { + // We're read()ing because if you attempt a ReadLine() at the end of the stream, it will lock up. + // With reading we can at least preemptively catch it before it locks (hence the hacky temporary workaround). + Console.Write((char)output.Read()); + i++; + } - Console.Write(c); - i++; + proc.Close(); + proc.Dispose(); + Console.ReadKey(); + } + catch (Exception e) + { + Console.WriteLine($"Caught an exception! We don't want to throw because we want MSBuild to continue to install." + + $"Message: {e.Message}" + + $"Inner Exception: {e.InnerException}" + + $"Stack Trace: {e.StackTrace}"); } - - proc.Close(); - proc.Dispose(); - Console.ReadKey(); } } } diff --git a/src/Package/MSBuild.VSSetup/exe.swr b/src/Package/MSBuild.VSSetup/exe.swr new file mode 100644 index 00000000000..86ebe2bf0be --- /dev/null +++ b/src/Package/MSBuild.VSSetup/exe.swr @@ -0,0 +1,20 @@ +use vs + +package name=Microsoft.Build.UnGAC + version=$(Version) + vs.package.type=exe + vs.package.chip=neutral + vs.package.language=neutral + vs.package.internalRevision=$(PackageInternalRevision) + +vs.installCommand fileName=[Payload] + +vs.repairCommand fileName=[Payload] + +vs.installSize + SystemDrive=0 + TargetDrive=0 + SharedDrive=0 + +vs.payloads + vs.payload source=!(bindpath.binaries.x86)\bin\i386\Microsoft.Build.UnGAC.exe \ 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) From b032a19c2d47fe0945b1df7b5071f7bf74cd5154 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Tue, 4 Aug 2020 14:48:53 -0700 Subject: [PATCH 04/24] catching my own nits --- src/Microsoft.Build.UnGAC/Program.cs | 65 ++++++++++++++++------------ 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.Build.UnGAC/Program.cs b/src/Microsoft.Build.UnGAC/Program.cs index 90dddaa2304..de8f852e262 100644 --- a/src/Microsoft.Build.UnGAC/Program.cs +++ b/src/Microsoft.Build.UnGAC/Program.cs @@ -24,7 +24,7 @@ static void Main(string[] args) StartInfo = new ProcessStartInfo { FileName = "C:\\Windows\\System32\\cmd.exe", - Arguments = "/k", // keep cmd open until we're done + Arguments = "/k", // Keep cmd open until we're done RedirectStandardOutput = true, RedirectStandardInput = true, UseShellExecute = false @@ -32,61 +32,70 @@ static void Main(string[] args) }; proc.Start(); - // hook into standard input/output of the process + // Hook into standard input/output of the process output = proc.StandardOutput; input = proc.StandardInput; - // use where.exe to find gacutil.exe - if (input.BaseStream.CanWrite) + if (!input.BaseStream.CanWrite) { - input.WriteLine("where /F /R \"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\" gacutil.exe"); + proc.Close(); + proc.Dispose(); + Console.WriteLine("Could not find instances of gacutil, exiting..."); + return; } - //throw away the first line - it's the command we just used + // Use where.exe to find gacutil.exe + input.WriteLine("where /F /R \"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\" gacutil.exe"); + + // Throw away the first line - it's the command we just used output.ReadLine(); string s = output.ReadLine(); - // store all instances of gacutil.exe - // doing this for now "just in case" + // Store all instances of gacutil for now. while (!String.IsNullOrEmpty(s)) { allInstancesOfGACUtil.Add(s); s = output.ReadLine(); } - if (allInstancesOfGACUtil.Count <= 0) + if (allInstancesOfGACUtil.Count == 0) { proc.Close(); + proc.Dispose(); Console.WriteLine("Could not find instances of gacutil, exiting..."); return; } - // we've found gacutil, now let's use it. + // We've found gacutil, now let's use it. string gacUtilExe = allInstancesOfGACUtil[0]; - if (input.BaseStream.CanWrite) + if (!input.BaseStream.CanWrite) { - input.WriteLine($"{gacUtilExe} /nologo /u \"MSBuild, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Conversion.Core, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Engine, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Tasks.Core, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Utilities.Core, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Framework, Version=15.1.0.0\"\n"); + proc.Close(); + proc.Dispose(); + Console.WriteLine("Could not find instances of gacutil, exiting..."); + return; } - //hacky temporary workaround - int i = 0; + input.WriteLine($"{gacUtilExe} /nologo /u \"MSBuild, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Engine, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Framework, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Tasks.Core, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Utilities.Core, Version=15.1.0.0\"\n" + + $"{gacUtilExe} /nologo /u \"Microsoft.Build.Conversion.Core, Version=15.1.0.0\"\n"); + + // This prevents output.ReadLine() from locking up below. + input.Flush(); + input.Close(); - // Peek is a strange beast. It returns a -1 if "no character can be read or if the stream does not support seeking." - // Yet there are cases where you can peek a -1 and read() returns a valid character. - // I've tested breakpoints where output.Peek() == -1 && output.BaseStream.CanSeek == true, but it never gets hit. - while (!(i > 2000 && output.Peek() == -1)) + s = output.ReadLine(); + + // Output everything gacutil returned. + while (s != null) { - // We're read()ing because if you attempt a ReadLine() at the end of the stream, it will lock up. - // With reading we can at least preemptively catch it before it locks (hence the hacky temporary workaround). - Console.Write((char)output.Read()); - i++; + Console.WriteLine(s); + s = output.ReadLine(); } proc.Close(); From 46155cbdcb9b272e970138fd8b3da40b8790fccb Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Tue, 4 Aug 2020 14:59:01 -0700 Subject: [PATCH 05/24] nits! --- src/Microsoft.Build.UnGAC/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.Build.UnGAC/Program.cs b/src/Microsoft.Build.UnGAC/Program.cs index de8f852e262..2a1aafa3480 100644 --- a/src/Microsoft.Build.UnGAC/Program.cs +++ b/src/Microsoft.Build.UnGAC/Program.cs @@ -40,7 +40,7 @@ static void Main(string[] args) { proc.Close(); proc.Dispose(); - Console.WriteLine("Could not find instances of gacutil, exiting..."); + Console.WriteLine("Could not use where.exe to find gacutil.exe. Exiting..."); return; } @@ -62,7 +62,7 @@ static void Main(string[] args) { proc.Close(); proc.Dispose(); - Console.WriteLine("Could not find instances of gacutil, exiting..."); + Console.WriteLine("Could not find instances of gacutil. Exiting..."); return; } @@ -73,7 +73,7 @@ static void Main(string[] args) { proc.Close(); proc.Dispose(); - Console.WriteLine("Could not find instances of gacutil, exiting..."); + Console.WriteLine("Could not write gacutil commands. Exiting..."); return; } From cacd72c2d7333674a04d5f8c87d0c9d9d4f116ed Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Fri, 7 Aug 2020 10:38:25 -0700 Subject: [PATCH 06/24] minor write update --- src/Microsoft.Build.UnGAC/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Build.UnGAC/Program.cs b/src/Microsoft.Build.UnGAC/Program.cs index 2a1aafa3480..f42868a0b68 100644 --- a/src/Microsoft.Build.UnGAC/Program.cs +++ b/src/Microsoft.Build.UnGAC/Program.cs @@ -104,7 +104,7 @@ static void Main(string[] args) } catch (Exception e) { - Console.WriteLine($"Caught an exception! We don't want to throw because we want MSBuild to continue to install." + + Console.WriteLine($"Caught an exception! We don't want to throw because we want MSBuild to install." + $"Message: {e.Message}" + $"Inner Exception: {e.InnerException}" + $"Stack Trace: {e.StackTrace}"); From 93d9f788e8abc3345de9ebb49c43858edd4d543f Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Wed, 12 Aug 2020 13:54:21 -0700 Subject: [PATCH 07/24] Minor PR feedback --- src/Microsoft.Build.UnGAC/Program.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.Build.UnGAC/Program.cs b/src/Microsoft.Build.UnGAC/Program.cs index f42868a0b68..f392b9e052f 100644 --- a/src/Microsoft.Build.UnGAC/Program.cs +++ b/src/Microsoft.Build.UnGAC/Program.cs @@ -49,13 +49,10 @@ static void Main(string[] args) // Throw away the first line - it's the command we just used output.ReadLine(); - string s = output.ReadLine(); - // Store all instances of gacutil for now. - while (!String.IsNullOrEmpty(s)) + for(string gacInstance = output.ReadLine(); !string.IsNullOrEmpty(gacInstance); gacInstance = output.ReadLine()) { - allInstancesOfGACUtil.Add(s); - s = output.ReadLine(); + allInstancesOfGACUtil.Add(gacInstance); } if (allInstancesOfGACUtil.Count == 0) @@ -89,13 +86,10 @@ static void Main(string[] args) input.Flush(); input.Close(); - s = output.ReadLine(); - // Output everything gacutil returned. - while (s != null) + for (string s = output.ReadLine(); s != null; s = output.ReadLine()) { Console.WriteLine(s); - s = output.ReadLine(); } proc.Close(); From 42a8bf58008e89795b8234e5a470fd5820b5a6a2 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Wed, 12 Aug 2020 14:59:16 -0700 Subject: [PATCH 08/24] Testing build without packageinternalrevision --- src/Package/MSBuild.VSSetup/exe.swr | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Package/MSBuild.VSSetup/exe.swr b/src/Package/MSBuild.VSSetup/exe.swr index 86ebe2bf0be..c24a23d8cdb 100644 --- a/src/Package/MSBuild.VSSetup/exe.swr +++ b/src/Package/MSBuild.VSSetup/exe.swr @@ -5,7 +5,6 @@ package name=Microsoft.Build.UnGAC vs.package.type=exe vs.package.chip=neutral vs.package.language=neutral - vs.package.internalRevision=$(PackageInternalRevision) vs.installCommand fileName=[Payload] From 3857ba1dba570cfca66ecf515fb4c530fbd23c02 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Wed, 19 Aug 2020 16:18:40 -0700 Subject: [PATCH 09/24] Using unmanaged code. Much cleaner! --- .../Microsoft.Build.UnGAC.csproj | 2 + src/Microsoft.Build.UnGAC/NativeMethods.cs | 22 +++++ src/Microsoft.Build.UnGAC/Program.cs | 93 ++++--------------- 3 files changed, 43 insertions(+), 74 deletions(-) create mode 100644 src/Microsoft.Build.UnGAC/NativeMethods.cs diff --git a/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj b/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj index e7749a96c0c..a67781554fe 100644 --- a/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj +++ b/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj @@ -34,6 +34,7 @@ + @@ -42,6 +43,7 @@ + diff --git a/src/Microsoft.Build.UnGAC/NativeMethods.cs b/src/Microsoft.Build.UnGAC/NativeMethods.cs new file mode 100644 index 00000000000..0c98ef59a04 --- /dev/null +++ b/src/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 +{ + [ComImport, Guid("E707DCDE-D1CD-11D2-BAB9-00C04F8ECEAE"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IAssemblyCache + { + [PreserveSig] + uint UninstallAssembly(uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pszAssemblyName, IntPtr refData, int pulDisposition); + } + + public static class NativeMethods + { + [DllImport("fusion.dll")] + internal static extern uint CreateAssemblyCache(out IAssemblyCache ppAsmCache, int dwReserved); + + } +} diff --git a/src/Microsoft.Build.UnGAC/Program.cs b/src/Microsoft.Build.UnGAC/Program.cs index f392b9e052f..5088a590e30 100644 --- a/src/Microsoft.Build.UnGAC/Program.cs +++ b/src/Microsoft.Build.UnGAC/Program.cs @@ -1,11 +1,4 @@ using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.ExceptionServices; -using System.Text; -using System.Threading.Tasks; namespace Microsoft.Build.UnGAC { @@ -15,85 +8,37 @@ static void Main(string[] args) { try { - List allInstancesOfGACUtil = new List(); - StreamReader output; - StreamWriter input; - - Process proc = new Process + string[] assembliesToUnGAC = { - StartInfo = new ProcessStartInfo - { - FileName = "C:\\Windows\\System32\\cmd.exe", - Arguments = "/k", // Keep cmd open until we're done - RedirectStandardOutput = true, - RedirectStandardInput = true, - UseShellExecute = false - } + "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" }; - proc.Start(); - - // Hook into standard input/output of the process - output = proc.StandardOutput; - input = proc.StandardInput; - - if (!input.BaseStream.CanWrite) - { - proc.Close(); - proc.Dispose(); - Console.WriteLine("Could not use where.exe to find gacutil.exe. Exiting..."); - return; - } - - // Use where.exe to find gacutil.exe - input.WriteLine("where /F /R \"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\" gacutil.exe"); - - // Throw away the first line - it's the command we just used - output.ReadLine(); - for(string gacInstance = output.ReadLine(); !string.IsNullOrEmpty(gacInstance); gacInstance = output.ReadLine()) - { - allInstancesOfGACUtil.Add(gacInstance); - } + uint hresult = NativeMethods.CreateAssemblyCache(out IAssemblyCache assemblyCache, 0); - if (allInstancesOfGACUtil.Count == 0) + // Most significant bit is set, meaning there was an error in the Hresult. + if ((hresult >> 31) == 1) { - proc.Close(); - proc.Dispose(); - Console.WriteLine("Could not find instances of gacutil. Exiting..."); + Console.WriteLine($"Could not successfully call CreateAssemblyCache. HResult: {hresult}"); + Console.WriteLine("Exiting without removing assemblies from the GAC..."); return; } - // We've found gacutil, now let's use it. - string gacUtilExe = allInstancesOfGACUtil[0]; - - if (!input.BaseStream.CanWrite) + for (int i = 0; i < assembliesToUnGAC.Length; i++) { - proc.Close(); - proc.Dispose(); - Console.WriteLine("Could not write gacutil commands. Exiting..."); - return; - } + hresult = assemblyCache.UninstallAssembly(0, assembliesToUnGAC[i], IntPtr.Zero, 0); - input.WriteLine($"{gacUtilExe} /nologo /u \"MSBuild, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Engine, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Framework, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Tasks.Core, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Utilities.Core, Version=15.1.0.0\"\n" + - $"{gacUtilExe} /nologo /u \"Microsoft.Build.Conversion.Core, Version=15.1.0.0\"\n"); - - // This prevents output.ReadLine() from locking up below. - input.Flush(); - input.Close(); - - // Output everything gacutil returned. - for (string s = output.ReadLine(); s != null; s = output.ReadLine()) - { - Console.WriteLine(s); + // If we hit an error with an assembly, keep trying the others. + if ((hresult >> 31) == 1) + { + Console.WriteLine($"Could not remove {assembliesToUnGAC[i]} from the GAC. HResult: {hresult}"); + } } - proc.Close(); - proc.Dispose(); Console.ReadKey(); } catch (Exception e) From 34883603abc587bff8ab6b55b33b739923620c58 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Thu, 20 Aug 2020 14:22:20 -0700 Subject: [PATCH 10/24] Fixing build error with xunit.console --- src/Microsoft.Build.UnGAC/App.config | 6 -- .../Microsoft.Build.UnGAC.csproj | 56 ++----------------- .../Properties/AssemblyInfo.cs | 36 ------------ 3 files changed, 5 insertions(+), 93 deletions(-) delete mode 100644 src/Microsoft.Build.UnGAC/App.config delete mode 100644 src/Microsoft.Build.UnGAC/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.Build.UnGAC/App.config b/src/Microsoft.Build.UnGAC/App.config deleted file mode 100644 index 8e15646352e..00000000000 --- a/src/Microsoft.Build.UnGAC/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj b/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj index a67781554fe..8c02b03edf5 100644 --- a/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj +++ b/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj @@ -1,54 +1,8 @@ - - - + + - Debug - AnyCPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621} Exe - Microsoft.Build.UnGAC - Microsoft.Build.UnGAC - v4.5 - 512 - true + net45 - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + diff --git a/src/Microsoft.Build.UnGAC/Properties/AssemblyInfo.cs b/src/Microsoft.Build.UnGAC/Properties/AssemblyInfo.cs deleted file mode 100644 index cd5dbc0fd44..00000000000 --- a/src/Microsoft.Build.UnGAC/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Microsoft.Build.UnGAC")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Microsoft.Build.UnGAC")] -[assembly: AssemblyCopyright("Copyright © 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("ed38be62-db5e-4dad-af05-2aa5594b1621")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] From 034d84d4d3eab5e642a55adeb938d4470a4a0ae9 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Wed, 26 Aug 2020 14:43:27 -0700 Subject: [PATCH 11/24] Moved exe.swr to its own directory. Otherwise both .swr files are passed to arcade as a semicolon delimited list, which arcade can't deal with --- MSBuild.sln | 35 ++++++++++++++- .../Microsoft.Build.UnGAC.csproj | 1 + .../MSBuild.UnGAC.VSSetup.csproj | 45 +++++++++++++++++++ .../exe.swr | 0 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/Package/MSBuild.UnGAC.VSSetup/MSBuild.UnGAC.VSSetup.csproj rename src/Package/{MSBuild.VSSetup => MSBuild.UnGAC.VSSetup}/exe.swr (100%) diff --git a/MSBuild.sln b/MSBuild.sln index b7ff1908291..a30c83cd449 100644 --- a/MSBuild.sln +++ b/MSBuild.sln @@ -65,7 +65,9 @@ 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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Build.UnGAC", "src\Microsoft.Build.UnGAC\Microsoft.Build.UnGAC.csproj", "{ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.UnGAC", "src\Microsoft.Build.UnGAC\Microsoft.Build.UnGAC.csproj", "{ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSBuild.UnGAC.VSSetup", "src\Package\MSBuild.UnGAC.VSSetup\MSBuild.UnGAC.VSSetup.csproj", "{F6480B5F-1E41-4451-8307-716CB019DC54}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -866,6 +868,36 @@ Global {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x64.Build.0 = Release-MONO|Any CPU {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|x64.ActiveCfg = Debug|x64 + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|x64.Build.0 = Debug|x64 + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|x86.ActiveCfg = Debug|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|x86.Build.0 = Debug|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|x64.ActiveCfg = Debug-MONO|x64 + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|x64.Build.0 = Debug-MONO|x64 + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|x64.ActiveCfg = MachineIndependent|x64 + {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|x64.Build.0 = MachineIndependent|x64 + {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|Any CPU.Build.0 = Release|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|x64.ActiveCfg = Release|x64 + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|x64.Build.0 = Release|x64 + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|x86.ActiveCfg = Release|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|x86.Build.0 = Release|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|x64.ActiveCfg = Release-MONO|x64 + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|x64.Build.0 = Release-MONO|x64 + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU + {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -882,6 +914,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} + {F6480B5F-1E41-4451-8307-716CB019DC54} = {9BAD9352-DEFB-45E5-B8A4-4816B9B22A33} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F948D667-14E3-4F98-BA50-3F3C948BF4C2} diff --git a/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj b/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj index 8c02b03edf5..6cdbeb5491c 100644 --- a/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj +++ b/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj @@ -3,6 +3,7 @@ Exe net45 + false diff --git a/src/Package/MSBuild.UnGAC.VSSetup/MSBuild.UnGAC.VSSetup.csproj b/src/Package/MSBuild.UnGAC.VSSetup/MSBuild.UnGAC.VSSetup.csproj new file mode 100644 index 00000000000..896afb11268 --- /dev/null +++ b/src/Package/MSBuild.UnGAC.VSSetup/MSBuild.UnGAC.VSSetup.csproj @@ -0,0 +1,45 @@ + + + + $(FullFrameworkTFM) + + Microsoft.Build.UnGAC.vsix + Microsoft.Build.UnGAC + + false + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Package/MSBuild.VSSetup/exe.swr b/src/Package/MSBuild.UnGAC.VSSetup/exe.swr similarity index 100% rename from src/Package/MSBuild.VSSetup/exe.swr rename to src/Package/MSBuild.UnGAC.VSSetup/exe.swr From 13042b80257c190439a147408ae4b9bf925502f8 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Mon, 31 Aug 2020 16:43:47 -0700 Subject: [PATCH 12/24] Transitioning UnGAC.Setup project to output its own .exe --- MSBuild.sln | 126 +++++++++--------- .../MSBuild.UnGAC.Setup.csproj} | 31 +++-- .../MSBuild.UnGAC.Setup/NativeMethods.cs | 22 +++ src/Package/MSBuild.UnGAC.Setup/Program.cs | 53 ++++++++ .../exe.swr | 2 +- 5 files changed, 158 insertions(+), 76 deletions(-) rename src/Package/{MSBuild.UnGAC.VSSetup/MSBuild.UnGAC.VSSetup.csproj => MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj} (63%) create mode 100644 src/Package/MSBuild.UnGAC.Setup/NativeMethods.cs create mode 100644 src/Package/MSBuild.UnGAC.Setup/Program.cs rename src/Package/{MSBuild.UnGAC.VSSetup => MSBuild.UnGAC.Setup}/exe.swr (79%) diff --git a/MSBuild.sln b/MSBuild.sln index a30c83cd449..7c47990e849 100644 --- a/MSBuild.sln +++ b/MSBuild.sln @@ -65,9 +65,9 @@ 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\Microsoft.Build.UnGAC\Microsoft.Build.UnGAC.csproj", "{ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.UnGAC", "src\Microsoft.Build.UnGAC\Microsoft.Build.UnGAC.csproj", "{FBB65818-1877-4BFD-AD5F-822A58E404BE}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSBuild.UnGAC.VSSetup", "src\Package\MSBuild.UnGAC.VSSetup\MSBuild.UnGAC.VSSetup.csproj", "{F6480B5F-1E41-4451-8307-716CB019DC54}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSBuild.UnGAC.Setup", "src\Package\MSBuild.UnGAC.Setup\MSBuild.UnGAC.Setup.csproj", "{572D934A-4725-43CD-9AD4-28F3A9796904}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -838,66 +838,66 @@ 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 - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x64.ActiveCfg = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x64.Build.0 = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x86.ActiveCfg = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x86.Build.0 = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x64.ActiveCfg = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x64.Build.0 = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x64.ActiveCfg = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x64.Build.0 = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|Any CPU.Build.0 = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x64.ActiveCfg = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x64.Build.0 = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x86.ActiveCfg = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x86.Build.0 = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x64.ActiveCfg = Release-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x64.Build.0 = Release-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|x64.ActiveCfg = Debug|x64 - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|x64.Build.0 = Debug|x64 - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|x86.ActiveCfg = Debug|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug|x86.Build.0 = Debug|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|x64.ActiveCfg = Debug-MONO|x64 - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|x64.Build.0 = Debug-MONO|x64 - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|x64.ActiveCfg = MachineIndependent|x64 - {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|x64.Build.0 = MachineIndependent|x64 - {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|Any CPU.Build.0 = Release|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|x64.ActiveCfg = Release|x64 - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|x64.Build.0 = Release|x64 - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|x86.ActiveCfg = Release|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release|x86.Build.0 = Release|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|x64.ActiveCfg = Release-MONO|x64 - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|x64.Build.0 = Release-MONO|x64 - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU - {F6480B5F-1E41-4451-8307-716CB019DC54}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|x64.ActiveCfg = Debug|x64 + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|x64.Build.0 = Debug|x64 + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|x86.ActiveCfg = Debug|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|x86.Build.0 = Debug|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|x64.ActiveCfg = Debug-MONO|x64 + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|x64.Build.0 = Debug-MONO|x64 + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|x64.ActiveCfg = MachineIndependent|x64 + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|x64.Build.0 = MachineIndependent|x64 + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|Any CPU.Build.0 = Release|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|x64.ActiveCfg = Release|x64 + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|x64.Build.0 = Release|x64 + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|x86.ActiveCfg = Release|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|x86.Build.0 = Release|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|x64.ActiveCfg = Release-MONO|x64 + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|x64.Build.0 = Release-MONO|x64 + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU + {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|Any CPU.Build.0 = Debug|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|x64.ActiveCfg = Debug|x64 + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|x64.Build.0 = Debug|x64 + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|x86.ActiveCfg = Debug|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|x86.Build.0 = Debug|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|x64.ActiveCfg = Debug-MONO|x64 + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|x64.Build.0 = Debug-MONO|x64 + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|x64.ActiveCfg = MachineIndependent|x64 + {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|x64.Build.0 = MachineIndependent|x64 + {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|Any CPU.ActiveCfg = Release|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|Any CPU.Build.0 = Release|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|x64.ActiveCfg = Release|x64 + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|x64.Build.0 = Release|x64 + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|x86.ActiveCfg = Release|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|x86.Build.0 = Release|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|x64.ActiveCfg = Release-MONO|x64 + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|x64.Build.0 = Release-MONO|x64 + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU + {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -914,7 +914,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} - {F6480B5F-1E41-4451-8307-716CB019DC54} = {9BAD9352-DEFB-45E5-B8A4-4816B9B22A33} + {572D934A-4725-43CD-9AD4-28F3A9796904} = {9BAD9352-DEFB-45E5-B8A4-4816B9B22A33} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F948D667-14E3-4F98-BA50-3F3C948BF4C2} diff --git a/src/Package/MSBuild.UnGAC.VSSetup/MSBuild.UnGAC.VSSetup.csproj b/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj similarity index 63% rename from src/Package/MSBuild.UnGAC.VSSetup/MSBuild.UnGAC.VSSetup.csproj rename to src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj index 896afb11268..1f40ee4f49f 100644 --- a/src/Package/MSBuild.UnGAC.VSSetup/MSBuild.UnGAC.VSSetup.csproj +++ b/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj @@ -1,45 +1,52 @@  - $(FullFrameworkTFM) + net45 + Exe - Microsoft.Build.UnGAC.vsix - Microsoft.Build.UnGAC + + Microsoft.Build.UnGAC.Setup false true - + + + <_SwixArgs Include="PackageType=manifest"/> + <_SwixArgs Include="TargetExt=.json"/> + + + - + + - + - + - - + - + - + --> diff --git a/src/Package/MSBuild.UnGAC.Setup/NativeMethods.cs b/src/Package/MSBuild.UnGAC.Setup/NativeMethods.cs new file mode 100644 index 00000000000..0c98ef59a04 --- /dev/null +++ b/src/Package/MSBuild.UnGAC.Setup/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 +{ + [ComImport, Guid("E707DCDE-D1CD-11D2-BAB9-00C04F8ECEAE"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IAssemblyCache + { + [PreserveSig] + uint UninstallAssembly(uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pszAssemblyName, IntPtr refData, int pulDisposition); + } + + public static class NativeMethods + { + [DllImport("fusion.dll")] + internal static extern uint CreateAssemblyCache(out IAssemblyCache ppAsmCache, int dwReserved); + + } +} diff --git a/src/Package/MSBuild.UnGAC.Setup/Program.cs b/src/Package/MSBuild.UnGAC.Setup/Program.cs new file mode 100644 index 00000000000..5088a590e30 --- /dev/null +++ b/src/Package/MSBuild.UnGAC.Setup/Program.cs @@ -0,0 +1,53 @@ +using System; + +namespace Microsoft.Build.UnGAC +{ + 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; + } + + for (int i = 0; i < assembliesToUnGAC.Length; i++) + { + hresult = assemblyCache.UninstallAssembly(0, assembliesToUnGAC[i], IntPtr.Zero, 0); + + // If we hit an error with an assembly, keep trying the others. + if ((hresult >> 31) == 1) + { + Console.WriteLine($"Could not remove {assembliesToUnGAC[i]} from the GAC. HResult: {hresult}"); + } + } + + Console.ReadKey(); + } + catch (Exception e) + { + Console.WriteLine($"Caught an exception! We don't want to throw because we want MSBuild to install." + + $"Message: {e.Message}" + + $"Inner Exception: {e.InnerException}" + + $"Stack Trace: {e.StackTrace}"); + } + } + } +} diff --git a/src/Package/MSBuild.UnGAC.VSSetup/exe.swr b/src/Package/MSBuild.UnGAC.Setup/exe.swr similarity index 79% rename from src/Package/MSBuild.UnGAC.VSSetup/exe.swr rename to src/Package/MSBuild.UnGAC.Setup/exe.swr index c24a23d8cdb..2cd9212cb9e 100644 --- a/src/Package/MSBuild.UnGAC.VSSetup/exe.swr +++ b/src/Package/MSBuild.UnGAC.Setup/exe.swr @@ -16,4 +16,4 @@ vs.installSize SharedDrive=0 vs.payloads - vs.payload source=!(bindpath.binaries.x86)\bin\i386\Microsoft.Build.UnGAC.exe \ No newline at end of file + vs.payload source=$(BinDir)MSBuild.UnGAC.Setup.exe From b52892fefe90c41a2139bc35d18a8efda02faa32 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Tue, 1 Sep 2020 11:27:40 -0700 Subject: [PATCH 13/24] Working state! (hopefully) --- src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj b/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj index 1f40ee4f49f..0b59a64d4e2 100644 --- a/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj +++ b/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj @@ -3,6 +3,7 @@ net45 Exe + MSBuild.UnGAC.Setup.json Microsoft.Build.UnGAC.Setup From be4ea05acc237649e34dc5e16bac88c9a85ea82c Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Tue, 1 Sep 2020 11:30:20 -0700 Subject: [PATCH 14/24] Remove unused ungac project --- MSBuild.sln | 32 ----------- .../Microsoft.Build.UnGAC.csproj | 9 ---- src/Microsoft.Build.UnGAC/NativeMethods.cs | 22 -------- src/Microsoft.Build.UnGAC/Program.cs | 53 ------------------- 4 files changed, 116 deletions(-) delete mode 100644 src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj delete mode 100644 src/Microsoft.Build.UnGAC/NativeMethods.cs delete mode 100644 src/Microsoft.Build.UnGAC/Program.cs diff --git a/MSBuild.sln b/MSBuild.sln index 7c47990e849..313c19c93f2 100644 --- a/MSBuild.sln +++ b/MSBuild.sln @@ -65,8 +65,6 @@ 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\Microsoft.Build.UnGAC\Microsoft.Build.UnGAC.csproj", "{FBB65818-1877-4BFD-AD5F-822A58E404BE}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSBuild.UnGAC.Setup", "src\Package\MSBuild.UnGAC.Setup\MSBuild.UnGAC.Setup.csproj", "{572D934A-4725-43CD-9AD4-28F3A9796904}" EndProject Global @@ -838,36 +836,6 @@ 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 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|x64.ActiveCfg = Debug|x64 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|x64.Build.0 = Debug|x64 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|x86.ActiveCfg = Debug|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug|x86.Build.0 = Debug|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|x64.ActiveCfg = Debug-MONO|x64 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|x64.Build.0 = Debug-MONO|x64 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|x64.ActiveCfg = MachineIndependent|x64 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|x64.Build.0 = MachineIndependent|x64 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|Any CPU.Build.0 = Release|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|x64.ActiveCfg = Release|x64 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|x64.Build.0 = Release|x64 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|x86.ActiveCfg = Release|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release|x86.Build.0 = Release|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|x64.ActiveCfg = Release-MONO|x64 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|x64.Build.0 = Release-MONO|x64 - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU - {FBB65818-1877-4BFD-AD5F-822A58E404BE}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|Any CPU.Build.0 = Debug|Any CPU {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj b/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj deleted file mode 100644 index 6cdbeb5491c..00000000000 --- a/src/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - Exe - net45 - false - - - diff --git a/src/Microsoft.Build.UnGAC/NativeMethods.cs b/src/Microsoft.Build.UnGAC/NativeMethods.cs deleted file mode 100644 index 0c98ef59a04..00000000000 --- a/src/Microsoft.Build.UnGAC/NativeMethods.cs +++ /dev/null @@ -1,22 +0,0 @@ -// 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 -{ - [ComImport, Guid("E707DCDE-D1CD-11D2-BAB9-00C04F8ECEAE"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - internal interface IAssemblyCache - { - [PreserveSig] - uint UninstallAssembly(uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pszAssemblyName, IntPtr refData, int pulDisposition); - } - - public static class NativeMethods - { - [DllImport("fusion.dll")] - internal static extern uint CreateAssemblyCache(out IAssemblyCache ppAsmCache, int dwReserved); - - } -} diff --git a/src/Microsoft.Build.UnGAC/Program.cs b/src/Microsoft.Build.UnGAC/Program.cs deleted file mode 100644 index 5088a590e30..00000000000 --- a/src/Microsoft.Build.UnGAC/Program.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; - -namespace Microsoft.Build.UnGAC -{ - 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; - } - - for (int i = 0; i < assembliesToUnGAC.Length; i++) - { - hresult = assemblyCache.UninstallAssembly(0, assembliesToUnGAC[i], IntPtr.Zero, 0); - - // If we hit an error with an assembly, keep trying the others. - if ((hresult >> 31) == 1) - { - Console.WriteLine($"Could not remove {assembliesToUnGAC[i]} from the GAC. HResult: {hresult}"); - } - } - - Console.ReadKey(); - } - catch (Exception e) - { - Console.WriteLine($"Caught an exception! We don't want to throw because we want MSBuild to install." + - $"Message: {e.Message}" + - $"Inner Exception: {e.InnerException}" + - $"Stack Trace: {e.StackTrace}"); - } - } - } -} From c53a3c08087a0b3a8c3a0183f2bf4cd7dfe770f5 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Tue, 1 Sep 2020 11:35:37 -0700 Subject: [PATCH 15/24] Cleanup --- MSBuild.Dev.sln | 32 ------------------- .../MSBuild.UnGAC.Setup.csproj | 26 +-------------- 2 files changed, 1 insertion(+), 57 deletions(-) diff --git a/MSBuild.Dev.sln b/MSBuild.Dev.sln index 253e38476e1..92050372dcc 100644 --- a/MSBuild.Dev.sln +++ b/MSBuild.Dev.sln @@ -33,8 +33,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.Utilities.U EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xunit.NetCore.Extensions", "src\Xunit.NetCore.Extensions\Xunit.NetCore.Extensions.csproj", "{66C6C1ED-30E7-45DD-9F73-2FBB7889CDBA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Build.UnGAC", "src\Microsoft.Build.UnGAC\Microsoft.Build.UnGAC.csproj", "{ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -414,36 +412,6 @@ Global {66C6C1ED-30E7-45DD-9F73-2FBB7889CDBA}.Release-MONO|x64.Build.0 = Release|x64 {66C6C1ED-30E7-45DD-9F73-2FBB7889CDBA}.Release-MONO|x86.ActiveCfg = Release|Any CPU {66C6C1ED-30E7-45DD-9F73-2FBB7889CDBA}.Release-MONO|x86.Build.0 = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x64.ActiveCfg = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x64.Build.0 = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x86.ActiveCfg = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug|x86.Build.0 = Debug|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x64.ActiveCfg = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x64.Build.0 = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x64.ActiveCfg = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x64.Build.0 = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|Any CPU.Build.0 = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x64.ActiveCfg = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x64.Build.0 = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x86.ActiveCfg = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release|x86.Build.0 = Release|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x64.ActiveCfg = Release-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x64.Build.0 = Release-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU - {ED38BE62-DB5E-4DAD-AF05-2AA5594B1621}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj b/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj index 0b59a64d4e2..fcfb4955365 100644 --- a/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj +++ b/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj @@ -5,17 +5,12 @@ Exe MSBuild.UnGAC.Setup.json - Microsoft.Build.UnGAC.Setup false true - - - - <_SwixArgs Include="PackageType=manifest"/> <_SwixArgs Include="TargetExt=.json"/> @@ -24,30 +19,11 @@ - + - - - - - - From 1c944fceda8b71a94a84821a0242a16a99fe4cc4 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Tue, 1 Sep 2020 11:49:44 -0700 Subject: [PATCH 16/24] csproj cleanup --- .../MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj b/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj index fcfb4955365..35626a75b78 100644 --- a/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj +++ b/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj @@ -6,9 +6,6 @@ MSBuild.UnGAC.Setup.json Microsoft.Build.UnGAC.Setup - - false - true @@ -16,14 +13,9 @@ <_SwixArgs Include="TargetExt=.json"/> - - - - - - + \ No newline at end of file From d1137ae805c9338b9f8626583fc1004e922035bb Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Tue, 1 Sep 2020 12:31:14 -0700 Subject: [PATCH 17/24] Basic documentation --- .../MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj b/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj index 35626a75b78..0e1d5324378 100644 --- a/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj +++ b/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj @@ -1,8 +1,11 @@  + net45 + Exe + MSBuild.UnGAC.Setup.json Microsoft.Build.UnGAC.Setup @@ -10,12 +13,17 @@ <_SwixArgs Include="PackageType=manifest"/> + <_SwixArgs Include="TargetExt=.json"/> + + + + \ No newline at end of file From f2d4c9e3658c01c0ad455c267e37906d94a9dfbf Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Wed, 2 Sep 2020 09:46:04 -0700 Subject: [PATCH 18/24] Remove readkey! --- src/Package/MSBuild.UnGAC.Setup/Program.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Package/MSBuild.UnGAC.Setup/Program.cs b/src/Package/MSBuild.UnGAC.Setup/Program.cs index 5088a590e30..481701958b9 100644 --- a/src/Package/MSBuild.UnGAC.Setup/Program.cs +++ b/src/Package/MSBuild.UnGAC.Setup/Program.cs @@ -38,8 +38,6 @@ static void Main(string[] args) Console.WriteLine($"Could not remove {assembliesToUnGAC[i]} from the GAC. HResult: {hresult}"); } } - - Console.ReadKey(); } catch (Exception e) { From 87e9bab133f4dd0e1e3e102328849e5ae0967d9d Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Wed, 2 Sep 2020 14:26:52 -0700 Subject: [PATCH 19/24] .exe now flows --- MSBuild.sln | 64 +++++++++---------- .../Microsoft.Build.UnGAC.csproj} | 9 ++- .../NativeMethods.cs | 0 .../Program.cs | 12 ++-- .../exe.swr | 2 +- 5 files changed, 43 insertions(+), 44 deletions(-) rename src/Package/{MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj => Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj} (71%) rename src/Package/{MSBuild.UnGAC.Setup => Microsoft.Build.UnGAC}/NativeMethods.cs (100%) rename src/Package/{MSBuild.UnGAC.Setup => Microsoft.Build.UnGAC}/Program.cs (80%) rename src/Package/{MSBuild.UnGAC.Setup => Microsoft.Build.UnGAC}/exe.swr (84%) diff --git a/MSBuild.sln b/MSBuild.sln index 313c19c93f2..966817afd12 100644 --- a/MSBuild.sln +++ b/MSBuild.sln @@ -65,7 +65,7 @@ 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}") = "MSBuild.UnGAC.Setup", "src\Package\MSBuild.UnGAC.Setup\MSBuild.UnGAC.Setup.csproj", "{572D934A-4725-43CD-9AD4-28F3A9796904}" +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 @@ -836,36 +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 - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|Any CPU.Build.0 = Debug|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|x64.ActiveCfg = Debug|x64 - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|x64.Build.0 = Debug|x64 - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|x86.ActiveCfg = Debug|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug|x86.Build.0 = Debug|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|x64.ActiveCfg = Debug-MONO|x64 - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|x64.Build.0 = Debug-MONO|x64 - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|x64.ActiveCfg = MachineIndependent|x64 - {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|x64.Build.0 = MachineIndependent|x64 - {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|Any CPU.ActiveCfg = Release|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|Any CPU.Build.0 = Release|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|x64.ActiveCfg = Release|x64 - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|x64.Build.0 = Release|x64 - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|x86.ActiveCfg = Release|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release|x86.Build.0 = Release|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|x64.ActiveCfg = Release-MONO|x64 - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|x64.Build.0 = Release-MONO|x64 - {572D934A-4725-43CD-9AD4-28F3A9796904}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU - {572D934A-4725-43CD-9AD4-28F3A9796904}.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 @@ -882,7 +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} - {572D934A-4725-43CD-9AD4-28F3A9796904} = {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/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj b/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj similarity index 71% rename from src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj rename to src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj index 0e1d5324378..1afd952c996 100644 --- a/src/Package/MSBuild.UnGAC.Setup/MSBuild.UnGAC.Setup.csproj +++ b/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj @@ -1,14 +1,13 @@ - - + - + net45 Exe - MSBuild.UnGAC.Setup.json + Microsoft.Build.UnGAC.exe - Microsoft.Build.UnGAC.Setup + Microsoft.Build.UnGAC diff --git a/src/Package/MSBuild.UnGAC.Setup/NativeMethods.cs b/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs similarity index 100% rename from src/Package/MSBuild.UnGAC.Setup/NativeMethods.cs rename to src/Package/Microsoft.Build.UnGAC/NativeMethods.cs diff --git a/src/Package/MSBuild.UnGAC.Setup/Program.cs b/src/Package/Microsoft.Build.UnGAC/Program.cs similarity index 80% rename from src/Package/MSBuild.UnGAC.Setup/Program.cs rename to src/Package/Microsoft.Build.UnGAC/Program.cs index 481701958b9..5639326ab82 100644 --- a/src/Package/MSBuild.UnGAC.Setup/Program.cs +++ b/src/Package/Microsoft.Build.UnGAC/Program.cs @@ -1,4 +1,7 @@ -using System; +// 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 { @@ -30,7 +33,7 @@ static void Main(string[] args) for (int i = 0; i < assembliesToUnGAC.Length; i++) { - hresult = assemblyCache.UninstallAssembly(0, assembliesToUnGAC[i], IntPtr.Zero, 0); + hresult = assemblyCache.UninstallAssembly(dwFlags: 0, pszAssemblyName: assembliesToUnGAC[i], refData: IntPtr.Zero, pulDisposition: 0); // If we hit an error with an assembly, keep trying the others. if ((hresult >> 31) == 1) @@ -41,10 +44,7 @@ static void Main(string[] args) } catch (Exception e) { - Console.WriteLine($"Caught an exception! We don't want to throw because we want MSBuild to install." + - $"Message: {e.Message}" + - $"Inner Exception: {e.InnerException}" + - $"Stack Trace: {e.StackTrace}"); + 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/MSBuild.UnGAC.Setup/exe.swr b/src/Package/Microsoft.Build.UnGAC/exe.swr similarity index 84% rename from src/Package/MSBuild.UnGAC.Setup/exe.swr rename to src/Package/Microsoft.Build.UnGAC/exe.swr index 2cd9212cb9e..9a717021a50 100644 --- a/src/Package/MSBuild.UnGAC.Setup/exe.swr +++ b/src/Package/Microsoft.Build.UnGAC/exe.swr @@ -16,4 +16,4 @@ vs.installSize SharedDrive=0 vs.payloads - vs.payload source=$(BinDir)MSBuild.UnGAC.Setup.exe + vs.payload source=$(BinDir)Microsoft.Build.UnGAC.exe From a63a2ad94f271cc46e8aad9d0cd069877a5d12b5 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Thu, 3 Sep 2020 14:22:44 -0700 Subject: [PATCH 20/24] PR Feedback, documentation. Reverted MSBuild.Dev.sln --- MSBuild.Dev.sln | 4 ++-- .../Microsoft.Build.UnGAC.csproj | 5 +++-- src/Package/Microsoft.Build.UnGAC/NativeMethods.cs | 4 +++- src/Package/Microsoft.Build.UnGAC/Program.cs | 12 +++++++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/MSBuild.Dev.sln b/MSBuild.Dev.sln index 92050372dcc..395bc1d6691 100644 --- a/MSBuild.Dev.sln +++ b/MSBuild.Dev.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30320.27 +# Visual Studio 15 +VisualStudioVersion = 15.0.27004.2009 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4900B3B8-4310-4D5B-B1F7-2FDF9199765F}" ProjectSection(SolutionItems) = preProject diff --git a/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj b/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj index 1afd952c996..c32f6b1cce1 100644 --- a/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj +++ b/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj @@ -16,12 +16,13 @@ <_SwixArgs Include="TargetExt=.json"/> - + - + + diff --git a/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs b/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs index 0c98ef59a04..661d5163288 100644 --- a/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs +++ b/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs @@ -6,11 +6,13 @@ 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 refData, int pulDisposition); + uint UninstallAssembly(uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pszAssemblyName, IntPtr pRefData, ref ulong pulDisposition); } public static class NativeMethods diff --git a/src/Package/Microsoft.Build.UnGAC/Program.cs b/src/Package/Microsoft.Build.UnGAC/Program.cs index 5639326ab82..259a40046ba 100644 --- a/src/Package/Microsoft.Build.UnGAC/Program.cs +++ b/src/Package/Microsoft.Build.UnGAC/Program.cs @@ -5,6 +5,12 @@ 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) @@ -31,14 +37,14 @@ static void Main(string[] args) return; } - for (int i = 0; i < assembliesToUnGAC.Length; i++) + foreach (string assembly in assembliesToUnGAC) { - hresult = assemblyCache.UninstallAssembly(dwFlags: 0, pszAssemblyName: assembliesToUnGAC[i], refData: IntPtr.Zero, pulDisposition: 0); + hresult = assemblyCache.UninstallAssembly(dwFlags: 0, pszAssemblyName: assembly, pRefData: IntPtr.Zero, pulDisposition: 0); // If we hit an error with an assembly, keep trying the others. if ((hresult >> 31) == 1) { - Console.WriteLine($"Could not remove {assembliesToUnGAC[i]} from the GAC. HResult: {hresult}"); + Console.WriteLine($"Could not remove {assembly} from the GAC. HResult: {hresult}"); } } } From 3cfb13ad905c408b80c875946d2c0e9556f4ac89 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Thu, 3 Sep 2020 14:39:46 -0700 Subject: [PATCH 21/24] Comment linking to the arcade bug. --- src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj b/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj index c32f6b1cce1..6282c3a2134 100644 --- a/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj +++ b/src/Package/Microsoft.Build.UnGAC/Microsoft.Build.UnGAC.csproj @@ -4,7 +4,7 @@ net45 Exe - + Microsoft.Build.UnGAC.exe Microsoft.Build.UnGAC From 49900b2cb05126a045134a50e6109e0efd87b6ff Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Thu, 3 Sep 2020 16:41:03 -0700 Subject: [PATCH 22/24] Add logging for removed assemblies. --- src/Package/Microsoft.Build.UnGAC/Program.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Package/Microsoft.Build.UnGAC/Program.cs b/src/Package/Microsoft.Build.UnGAC/Program.cs index 259a40046ba..70bed6cb7b0 100644 --- a/src/Package/Microsoft.Build.UnGAC/Program.cs +++ b/src/Package/Microsoft.Build.UnGAC/Program.cs @@ -46,6 +46,10 @@ static void Main(string[] args) { Console.WriteLine($"Could not remove {assembly} from the GAC. HResult: {hresult}"); } + else + { + Console.WriteLine($"Removed {assembly} from the GAC. HResult: {hresult}"); + } } } catch (Exception e) From e89501e67e07fe474a70153e5df3766d27db0085 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Fri, 4 Sep 2020 15:06:41 -0700 Subject: [PATCH 23/24] Sign UnGAC.exe --- eng/Signing.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 60039b62f4afa13f2811f80ea5cc36c079d36770 Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Fri, 18 Sep 2020 11:43:47 -0700 Subject: [PATCH 24/24] Changes from review --- src/Package/Microsoft.Build.UnGAC/NativeMethods.cs | 2 -- src/Package/Microsoft.Build.UnGAC/Program.cs | 10 +--------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs b/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs index 661d5163288..f468942cf12 100644 --- a/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs +++ b/src/Package/Microsoft.Build.UnGAC/NativeMethods.cs @@ -7,7 +7,6 @@ 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 { @@ -19,6 +18,5 @@ 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 index 70bed6cb7b0..c5b5caa710d 100644 --- a/src/Package/Microsoft.Build.UnGAC/Program.cs +++ b/src/Package/Microsoft.Build.UnGAC/Program.cs @@ -41,15 +41,7 @@ static void Main(string[] args) { hresult = assemblyCache.UninstallAssembly(dwFlags: 0, pszAssemblyName: assembly, pRefData: IntPtr.Zero, pulDisposition: 0); - // If we hit an error with an assembly, keep trying the others. - if ((hresult >> 31) == 1) - { - Console.WriteLine($"Could not remove {assembly} from the GAC. HResult: {hresult}"); - } - else - { - Console.WriteLine($"Removed {assembly} from the GAC. HResult: {hresult}"); - } + Console.WriteLine($"Tried to remove {assembly} from the GAC. HResult: 0x{hresult:X8}"); } } catch (Exception e)