winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 8cb0de07d171bec2022f624392fc125a4c071cc3
parent 3a5889b8070a0a4675c128495636ff9e6dac6084
Author: Ruben Guerrero <rubengu@microsoft.com>
Date:   Thu, 25 May 2023 11:10:39 -0700

Add Microsoft.WinGet.Configuration module to ReleaseStatic configuration (#3262)

Add Microsoft.WinGet.Configuration module to ReleaseStatic configuration
Fix WinRT.Runtime.dll ALC issue.
Manually add AssemblyInfo.cs.
Fix bug where messages where not being shown when Start-WinGetConfiguration was piped to Complete-WinGetConfiguration
Diffstat:
Msrc/AppInstallerCLI.sln | 18++++++++++++------
Msrc/Microsoft.Management.Configuration.Processor/Microsoft.Management.Configuration.Processor.csproj | 5+++++
Msrc/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Acl/CustomAssemblyLoadContext.cs | 24++++++++++++++++++++++++
Msrc/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Microsoft.WinGet.Configuration.Cmdlets.csproj | 7+++++++
Asrc/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Properties/AssemblyInfo.cs | 17+++++++++++++++++
Msrc/PowerShell/Microsoft.WinGet.Configuration.Engine/Commands/AsyncCommand.cs | 32++++++++++++++++++--------------
Msrc/PowerShell/Microsoft.WinGet.Configuration.Engine/Commands/ConfigurationCommand.cs | 4++--
Msrc/PowerShell/Microsoft.WinGet.Configuration.Engine/Microsoft.WinGet.Configuration.Engine.csproj | 7+++++++
Asrc/PowerShell/Microsoft.WinGet.Configuration.Engine/Properties/AssemblyInfo.cs | 17+++++++++++++++++
9 files changed, 109 insertions(+), 22 deletions(-)

diff --git a/src/AppInstallerCLI.sln b/src/AppInstallerCLI.sln @@ -997,8 +997,10 @@ Global {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.Fuzzing|x86.ActiveCfg = Debug|Any CPU {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.Fuzzing|x86.Build.0 = Debug|Any CPU {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|ARM64.ActiveCfg = Release|Any CPU - {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x64.ActiveCfg = Release|Any CPU - {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x86.ActiveCfg = Release|Any CPU + {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x64.ActiveCfg = ReleaseStatic|Any CPU + {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x64.Build.0 = ReleaseStatic|Any CPU + {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x86.ActiveCfg = ReleaseStatic|Any CPU + {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.PowerShell|x86.Build.0 = ReleaseStatic|Any CPU {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.Release|ARM64.ActiveCfg = Release|Any CPU {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.Release|ARM64.Build.0 = Release|Any CPU {71FA29AA-9035-468B-A11D-0F0B0F5D5AF4}.Release|x64.ActiveCfg = Release|Any CPU @@ -1080,8 +1082,10 @@ Global {167F634B-A3AD-494E-8E67-B888103E35FF}.Fuzzing|x86.ActiveCfg = Debug|Any CPU {167F634B-A3AD-494E-8E67-B888103E35FF}.Fuzzing|x86.Build.0 = Debug|Any CPU {167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|ARM64.ActiveCfg = Release|Any CPU - {167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x64.ActiveCfg = Release|Any CPU - {167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x86.ActiveCfg = Release|Any CPU + {167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x64.ActiveCfg = ReleaseStatic|Any CPU + {167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x64.Build.0 = ReleaseStatic|Any CPU + {167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x86.ActiveCfg = ReleaseStatic|Any CPU + {167F634B-A3AD-494E-8E67-B888103E35FF}.PowerShell|x86.Build.0 = ReleaseStatic|Any CPU {167F634B-A3AD-494E-8E67-B888103E35FF}.Release|ARM64.ActiveCfg = Release|Any CPU {167F634B-A3AD-494E-8E67-B888103E35FF}.Release|ARM64.Build.0 = Release|Any CPU {167F634B-A3AD-494E-8E67-B888103E35FF}.Release|x64.ActiveCfg = Release|Any CPU @@ -1107,8 +1111,10 @@ Global {C54F80ED-B736-49B0-9BD3-662F57024D01}.Fuzzing|x86.ActiveCfg = Debug|Any CPU {C54F80ED-B736-49B0-9BD3-662F57024D01}.Fuzzing|x86.Build.0 = Debug|Any CPU {C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|ARM64.ActiveCfg = Release|Any CPU - {C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x64.ActiveCfg = Release|Any CPU - {C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x86.ActiveCfg = Release|Any CPU + {C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x64.ActiveCfg = ReleaseStatic|Any CPU + {C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x64.Build.0 = ReleaseStatic|Any CPU + {C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x86.ActiveCfg = ReleaseStatic|Any CPU + {C54F80ED-B736-49B0-9BD3-662F57024D01}.PowerShell|x86.Build.0 = ReleaseStatic|Any CPU {C54F80ED-B736-49B0-9BD3-662F57024D01}.Release|ARM64.ActiveCfg = Release|Any CPU {C54F80ED-B736-49B0-9BD3-662F57024D01}.Release|ARM64.Build.0 = Release|Any CPU {C54F80ED-B736-49B0-9BD3-662F57024D01}.Release|x64.ActiveCfg = Release|Any CPU diff --git a/src/Microsoft.Management.Configuration.Processor/Microsoft.Management.Configuration.Processor.csproj b/src/Microsoft.Management.Configuration.Processor/Microsoft.Management.Configuration.Processor.csproj @@ -16,12 +16,17 @@ <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch> <!-- Disable warning for CS1591 for cswinrt auto-generated files --> <NoWarn>1591</NoWarn> + <Configurations>Debug;Release;ReleaseStatic</Configurations> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)'=='Release'"> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)'=='ReleaseStatic'"> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + </PropertyGroup> + <PropertyGroup> <CsWinRTComponent>true</CsWinRTComponent> <CsWinRTWindowsMetadata>10.0.19041.0</CsWinRTWindowsMetadata> diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Acl/CustomAssemblyLoadContext.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Acl/CustomAssemblyLoadContext.cs @@ -19,6 +19,14 @@ namespace Microsoft.WinGet.Configuration.Acl /// </summary> internal class CustomAssemblyLoadContext : AssemblyLoadContext { + // The assemblies must be loaded in the default context. + // Loading WinRT.Runtime.dll in an ALC when is already loaded in the default context + // will result on 'Attempt to update previously set global instance.' + private static readonly IEnumerable<string> DefaultContextAssemblies = new string[] + { + @"WinRT.Runtime.dll", + }; + private static readonly string SharedDependencyPath = Path.Combine( Path.GetDirectoryName(typeof(CustomAssemblyLoadContext).Assembly.Location), "SharedDependencies"); @@ -64,6 +72,16 @@ namespace Microsoft.WinGet.Configuration.Acl /// <returns>The assembly, null if not in our assembly location.</returns> internal static Assembly ResolvingHandler(AssemblyLoadContext context, AssemblyName assemblyName) { + string name = $"{assemblyName.Name}.dll"; + if (DefaultContextAssemblies.Any(a => a.Equals(name, StringComparison.OrdinalIgnoreCase))) + { + string sharedPath = Path.Combine(SharedDependencyPath, name); + if (File.Exists(sharedPath)) + { + return AssemblyLoadContext.Default.LoadFromAssemblyPath(sharedPath); + } + } + string path = $"{Path.Combine(DirectDependencyPath, assemblyName.Name)}.dll"; if (File.Exists(path)) { @@ -76,6 +94,12 @@ namespace Microsoft.WinGet.Configuration.Acl /// <inheritdoc/> protected override Assembly Load(AssemblyName assemblyName) { + string name = $"{assemblyName.Name}.dll"; + if (DefaultContextAssemblies.Any(a => a.Equals(name, StringComparison.OrdinalIgnoreCase))) + { + return null; + } + string path = $"{Path.Combine(SharedDependencyPath, assemblyName.Name)}.dll"; if (File.Exists(path)) { diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Microsoft.WinGet.Configuration.Cmdlets.csproj b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Microsoft.WinGet.Configuration.Cmdlets.csproj @@ -1,19 +1,26 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> + <!-- Keep in sync with attributes in AssemblyInfo.cs --> <TargetFramework>net6.0-windows10.0.19041</TargetFramework> + <GenerateAssemblyInfo>false</GenerateAssemblyInfo> <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\</OutputPath> <GenerateDocumentationFile>true</GenerateDocumentationFile> <DocumentationFile>$(OutputPath)\$(MSBuildProjectName).xml</DocumentationFile> <RuntimeIdentifier>win</RuntimeIdentifier> <BuildOutputDirectory>$(SolutionDir)$(Platform)\$(Configuration)\</BuildOutputDirectory> <RootNamespace>Microsoft.WinGet.Configuration</RootNamespace> + <Configurations>Debug;Release;ReleaseStatic</Configurations> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)'=='Release'"> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)'=='ReleaseStatic'"> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + </PropertyGroup> + <ItemGroup> <AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" /> </ItemGroup> diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Properties/AssemblyInfo.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Properties/AssemblyInfo.cs @@ -0,0 +1,16 @@ +// ----------------------------------------------------------------------------- +// <copyright file="AssemblyInfo.cs" company="Microsoft Corporation"> +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// </copyright> +// ----------------------------------------------------------------------------- + +#if NET + +using System.Runtime.Versioning; + +// Forcibly set the target and supported platforms due to the internal build setup. +// Keep in sync with project versions. +[assembly: TargetPlatform("Windows10.0.19041.0")] +[assembly: SupportedOSPlatform("Windows10.0.18362.0")] + +#endif+ \ No newline at end of file diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Commands/AsyncCommand.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Commands/AsyncCommand.cs @@ -194,8 +194,11 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands /// Waits for the task to be completed. This MUST be called from the main thread. /// </summary> /// <param name="runningTask">Task to wait for.</param> - internal void Wait(Task runningTask) + /// <param name="writeCommand">The command that can write to PowerShell.</param> + internal void Wait(Task runningTask, AsyncCommand? writeCommand = null) { + writeCommand ??= this; + // This must be called in the main thread. if (this.originalThread != Thread.CurrentThread) { @@ -204,9 +207,9 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands do { - this.ConsumeStreams(); + this.ConsumeAndWriteStreams(writeCommand); } - while (!runningTask.IsCompleted && this.queuedStreams.IsCompleted); + while (!(runningTask.IsCompleted && this.queuedStreams.IsCompleted)); if (runningTask.IsFaulted) { @@ -237,7 +240,7 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands if (this.originalThread == Thread.CurrentThread) { - this.CmdletWrite(type, data); + this.CmdletWrite(type, data, this); return; } @@ -319,7 +322,8 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands /// This method must be called in the original thread. /// WARNING: You must only call this when the task is completed or in Wait. /// </summary> - internal void ConsumeStreams() + /// <param name="writeCommand">The command that can write to PowerShell.</param> + internal void ConsumeAndWriteStreams(AsyncCommand writeCommand) { // This must be called in the main thread. if (this.originalThread != Thread.CurrentThread) @@ -335,7 +339,7 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands var queuedOutput = this.queuedStreams.Take(); if (queuedOutput != null) { - this.CmdletWrite(queuedOutput.Type, queuedOutput.Data); + this.CmdletWrite(queuedOutput.Type, queuedOutput.Data, writeCommand); } } } @@ -355,36 +359,36 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands return Interlocked.Increment(ref this.progressActivityId); } - private void CmdletWrite(StreamType streamType, object data) + private void CmdletWrite(StreamType streamType, object data, AsyncCommand writeCommand) { switch (streamType) { case StreamType.Debug: - this.PsCmdlet.WriteDebug((string)data); + writeCommand.PsCmdlet.WriteDebug((string)data); break; case StreamType.Verbose: - this.PsCmdlet.WriteVerbose((string)data); + writeCommand.PsCmdlet.WriteVerbose((string)data); break; case StreamType.Warning: - this.PsCmdlet.WriteWarning((string)data); + writeCommand.PsCmdlet.WriteWarning((string)data); break; case StreamType.Error: - this.PsCmdlet.WriteError((ErrorRecord)data); + writeCommand.PsCmdlet.WriteError((ErrorRecord)data); break; case StreamType.Progress: // If the activity is already completed don't write progress. var progressRecord = (ProgressRecord)data; if (this.progressRecords[progressRecord.ActivityId] == ProgressRecordType.Processing) { - this.PsCmdlet.WriteProgress(progressRecord); + writeCommand.PsCmdlet.WriteProgress(progressRecord); } break; case StreamType.Object: - this.PsCmdlet.WriteObject(data); + writeCommand.PsCmdlet.WriteObject(data); break; case StreamType.Information: - this.PsCmdlet.WriteInformation(data, WriteInformationTags); + writeCommand.PsCmdlet.WriteInformation(data, WriteInformationTags); break; } } diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Commands/ConfigurationCommand.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Commands/ConfigurationCommand.cs @@ -177,7 +177,7 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands if (psConfigurationJob.ConfigurationTask.IsCompleted) { // It is safe to print all output. - psConfigurationJob.StartCommand.ConsumeStreams(); + psConfigurationJob.StartCommand.ConsumeAndWriteStreams(this); this.Write(StreamType.Verbose, "The task was completed before waiting"); if (psConfigurationJob.ConfigurationTask.IsCompletedSuccessfully) @@ -225,7 +225,7 @@ namespace Microsoft.WinGet.Configuration.Engine.Commands { // Signal the command that it can write to streams and wait for task. this.Write(StreamType.Verbose, "Waiting for task to complete"); - psConfigurationJob.StartCommand.Wait(psConfigurationJob.ConfigurationTask); + psConfigurationJob.StartCommand.Wait(psConfigurationJob.ConfigurationTask, this); this.Write(StreamType.Object, psConfigurationJob.ConfigurationTask.Result); } diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Microsoft.WinGet.Configuration.Engine.csproj b/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Microsoft.WinGet.Configuration.Engine.csproj @@ -1,18 +1,25 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> + <!-- Keep in sync with attributes in AssemblyInfo.cs --> <TargetFramework>net6.0-windows10.0.19041</TargetFramework> + <GenerateAssemblyInfo>false</GenerateAssemblyInfo> <Nullable>enable</Nullable> <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\</OutputPath> <GenerateDocumentationFile>true</GenerateDocumentationFile> <DocumentationFile>$(OutputPath)\$(MSBuildProjectName).xml</DocumentationFile> <RuntimeIdentifier>win</RuntimeIdentifier> + <Configurations>Debug;Release;ReleaseStatic</Configurations> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)'=='Release'"> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)'=='ReleaseStatic'"> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + </PropertyGroup> + <ItemGroup> <AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" /> </ItemGroup> diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Properties/AssemblyInfo.cs b/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Properties/AssemblyInfo.cs @@ -0,0 +1,16 @@ +// ----------------------------------------------------------------------------- +// <copyright file="AssemblyInfo.cs" company="Microsoft Corporation"> +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// </copyright> +// ----------------------------------------------------------------------------- + +#if NET + +using System.Runtime.Versioning; + +// Forcibly set the target and supported platforms due to the internal build setup. +// Keep in sync with project versions. +[assembly: TargetPlatform("Windows10.0.19041.0")] +[assembly: SupportedOSPlatform("Windows10.0.18362.0")] + +#endif+ \ No newline at end of file