-
Notifications
You must be signed in to change notification settings - Fork 1.4k
UnGAC MSBuild Assemblies on Install or Update #5626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3b39127
ae20d69
cbbd763
b032a19
46155cb
cacd72c
93d9f78
42a8bf5
3857ba1
3488360
034d84d
13042b8
b52892f
be4ea05
c53a3c0
1c944fc
d1137ae
f2d4c9e
87e9bab
a63a2ad
3cfb13a
49900b2
e89501e
60039b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <!-- Setup runs on net45 and may not have installed newer yet. --> | ||
| <TargetFramework>net45</TargetFramework> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that mean it doesn't work on mac/linux? Is there a way we can make it work on mac/linux?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The GAC is a thing only on .NET Framework (on Windows). Things do not break because of the GAC on Mac/Linux, because there's no GAC. |
||
| <!-- Set as an exe because this project publishes its own output. --> | ||
| <OutputType>Exe</OutputType> | ||
| <!-- Forcing the 'vsix' output to be json output. Workaround for https://github.com/dotnet/arcade/issues/6120 --> | ||
| <TargetVsixContainerName>Microsoft.Build.UnGAC.exe</TargetVsixContainerName> | ||
| <!-- VS Insertion --> | ||
| <VisualStudioInsertionComponent>Microsoft.Build.UnGAC</VisualStudioInsertionComponent> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <_SwixArgs Include="PackageType=manifest"/> | ||
| <!-- If we don't set TargetExt to .json, arcade defaults to generating a .vsix --> | ||
| <_SwixArgs Include="TargetExt=.json"/> | ||
| </ItemGroup> | ||
|
|
||
| <!-- SwrProperty is an arcade concept. --> | ||
| <ItemGroup> | ||
| <!-- BinDir is set via SwrProperty to be passed to the swr compiler. OutDir is the path to the bin folder. See exe.swr to see how this is used. --> | ||
| <SwrProperty Include="BinDir=$(OutDir)" /> | ||
| <!-- Version must constantly update in order for our exe package to run on install and update. --> | ||
| <SwrProperty Include="Version=$(VsixVersion)" /> | ||
|
|
||
| <!-- our swr file must be picked up, this is how we set that. --> | ||
| <SwrFile Include="exe.swr" Condition=" '$(MSBuildRuntimeType)' == 'Full' " /> | ||
| </ItemGroup> | ||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Microsoft.Build.UnGAC | ||
| { | ||
| // See: https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-api/fusion/iassemblycache-interface | ||
| [ComImport, Guid("E707DCDE-D1CD-11D2-BAB9-00C04F8ECEAE"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
| internal interface IAssemblyCache | ||
| { | ||
| [PreserveSig] | ||
| uint UninstallAssembly(uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pszAssemblyName, IntPtr pRefData, ref ulong pulDisposition); | ||
| } | ||
|
|
||
| public static class NativeMethods | ||
| { | ||
| [DllImport("fusion.dll")] | ||
| internal static extern uint CreateAssemblyCache(out IAssemblyCache ppAsmCache, int dwReserved); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Build.UnGAC | ||
| { | ||
| /// <summary> | ||
| /// 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. | ||
| /// </summary> | ||
| class Program | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: generic name |
||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| try | ||
| { | ||
| string[] assembliesToUnGAC = | ||
| { | ||
| "Microsoft.Build, Version=15.1.0.0", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these the only versions people GAC?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're the only versions that we use, so they're the only ones that need to be removed from the GAC. Prior to VS 15, our assemblies were GACed by design; after they're not and they're all |
||
| "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}"); | ||
|
benvillalobos marked this conversation as resolved.
|
||
| Console.WriteLine("Exiting without removing assemblies from the GAC..."); | ||
| return; | ||
| } | ||
|
|
||
| foreach (string assembly in assembliesToUnGAC) | ||
| { | ||
| hresult = assemblyCache.UninstallAssembly(dwFlags: 0, pszAssemblyName: assembly, pRefData: IntPtr.Zero, pulDisposition: 0); | ||
|
|
||
| Console.WriteLine($"Tried to remove {assembly} from the GAC. HResult: 0x{hresult:X8}"); | ||
| } | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.WriteLine($"Caught an exception! We don't want to throw because we want MSBuild to install.\n" + e.ToString()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| use vs | ||
|
|
||
| package name=Microsoft.Build.UnGAC | ||
| version=$(Version) | ||
| vs.package.type=exe | ||
| vs.package.chip=neutral | ||
| vs.package.language=neutral | ||
|
|
||
| vs.installCommand fileName=[Payload] | ||
|
|
||
| vs.repairCommand fileName=[Payload] | ||
|
|
||
| vs.installSize | ||
| SystemDrive=0 | ||
| TargetDrive=0 | ||
| SharedDrive=0 | ||
|
|
||
| vs.payloads | ||
| vs.payload source=$(BinDir)Microsoft.Build.UnGAC.exe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused by this; do we not need to sign DevDivPackages*.nupkg anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't sign it in the first place; this line was just in error.