From 52331e58045afeed283fa3847526dd7732ed8563 Mon Sep 17 00:00:00 2001 From: Todd Grunke Date: Mon, 18 Mar 2024 14:08:25 -0700 Subject: [PATCH] Pass the temp path to DesktopStrongNameProvider ctor This addresses feedback ticket: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1950505 The underlying issue here is that the DesktopStrongNameProvider assumes it's caller will pass it a temp directory as EmitStream.CreateStream fails if the path isn't set. Jared indicated the compiler has a ban on calling Path.GetTempPath within their codebase, so it's on the caller to specify a value. --- eng/config/BannedSymbols.txt | 1 + .../Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs | 2 +- .../Serialization/AbstractOptionsSerializationService.cs | 3 ++- .../Core/Portable/Serialization/SerializationExtensions.cs | 3 ++- src/Workspaces/Core/Portable/Workspace/CommandLineProject.cs | 2 +- .../ProjectSystem/ProjectSystemProjectOptionsProcessor.cs | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/eng/config/BannedSymbols.txt b/eng/config/BannedSymbols.txt index 42fd708fa29ec..631138488c6ed 100644 --- a/eng/config/BannedSymbols.txt +++ b/eng/config/BannedSymbols.txt @@ -70,4 +70,5 @@ M:Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(System M:Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(System.Threading.CancellationToken); Use overload that takes progress M:Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(CSystem.Threading.CancellationToken); Use overload that takes progress M:Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedDocumentAsync(CancellationToken); Use overload that takes progress +M:Microsoft.CodeAnalysis.DesktopStrongNameProvider.#ctor(System.Collections.Immutable.ImmutableArray{System.String}); Use overload that takes in temp directory M:System.Diagnostics.Tracing.EventSource.WriteEvent(System.Int32,System.Object[]); Use WriteEventCore instead \ No newline at end of file diff --git a/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs b/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs index cfd33c1999c2d..c20e6b522a7a4 100644 --- a/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs +++ b/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs @@ -352,7 +352,7 @@ private Task CreateProjectInfoAsync(ProjectFileInfo projectFileInfo .WithSourceReferenceResolver(new SourceFileResolver([], projectDirectory)) // TODO: https://github.com/dotnet/roslyn/issues/4967 .WithMetadataReferenceResolver(new WorkspaceMetadataFileReferenceResolver(metadataService, new RelativePathResolver([], projectDirectory))) - .WithStrongNameProvider(new DesktopStrongNameProvider(commandLineArgs.KeyFileSearchPaths)) + .WithStrongNameProvider(new DesktopStrongNameProvider(commandLineArgs.KeyFileSearchPaths, Path.GetTempPath())) .WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default); var documents = CreateDocumentInfos(projectFileInfo.Documents, projectId, commandLineArgs.Encoding); diff --git a/src/Workspaces/Core/Portable/Serialization/AbstractOptionsSerializationService.cs b/src/Workspaces/Core/Portable/Serialization/AbstractOptionsSerializationService.cs index 89535cf1d281f..3a296dba72ee3 100644 --- a/src/Workspaces/Core/Portable/Serialization/AbstractOptionsSerializationService.cs +++ b/src/Workspaces/Core/Portable/Serialization/AbstractOptionsSerializationService.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Collections.Immutable; +using System.IO; using System.Linq; using System.Threading; using Roslyn.Utilities; @@ -158,7 +159,7 @@ protected static ( var xmlReferenceResolver = XmlFileResolver.Default; var sourceReferenceResolver = SourceFileResolver.Default; var assemblyIdentityComparer = DesktopAssemblyIdentityComparer.Default; - var strongNameProvider = new DesktopStrongNameProvider(); + var strongNameProvider = new DesktopStrongNameProvider(ImmutableArray.Empty, Path.GetTempPath()); return ( outputKind, diff --git a/src/Workspaces/Core/Portable/Serialization/SerializationExtensions.cs b/src/Workspaces/Core/Portable/Serialization/SerializationExtensions.cs index 7d8890d20a2c6..76aa8fd1e4438 100644 --- a/src/Workspaces/Core/Portable/Serialization/SerializationExtensions.cs +++ b/src/Workspaces/Core/Portable/Serialization/SerializationExtensions.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Immutable; +using System.IO; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Text; @@ -37,7 +38,7 @@ public static WellKnownSynchronizationKind GetWellKnownSynchronizationKind(this public static CompilationOptions FixUpCompilationOptions(this ProjectInfo.ProjectAttributes info, CompilationOptions compilationOptions) { return compilationOptions.WithXmlReferenceResolver(GetXmlResolver(info.FilePath)) - .WithStrongNameProvider(new DesktopStrongNameProvider(GetStrongNameKeyPaths(info))); + .WithStrongNameProvider(new DesktopStrongNameProvider(GetStrongNameKeyPaths(info), Path.GetTempPath())); } private static XmlFileResolver GetXmlResolver(string? filePath) diff --git a/src/Workspaces/Core/Portable/Workspace/CommandLineProject.cs b/src/Workspaces/Core/Portable/Workspace/CommandLineProject.cs index 1929d87449ef5..b01bdd20308ee 100644 --- a/src/Workspaces/Core/Portable/Workspace/CommandLineProject.cs +++ b/src/Workspaces/Core/Portable/Workspace/CommandLineProject.cs @@ -44,7 +44,7 @@ public static ProjectInfo CreateProjectInfo(string projectName, string language, var analyzerLoader = languageServices.SolutionServices.GetRequiredService().GetLoader(); var xmlFileResolver = new XmlFileResolver(commandLineArguments.BaseDirectory); - var strongNameProvider = new DesktopStrongNameProvider(commandLineArguments.KeyFileSearchPaths); + var strongNameProvider = new DesktopStrongNameProvider(commandLineArguments.KeyFileSearchPaths, Path.GetTempPath()); // Resolve all metadata references. // diff --git a/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectOptionsProcessor.cs b/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectOptionsProcessor.cs index 079e415d70645..11be0ef802128 100644 --- a/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectOptionsProcessor.cs +++ b/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectOptionsProcessor.cs @@ -192,7 +192,7 @@ private void UpdateProjectOptions_NoLock() .WithConcurrentBuild(concurrent: false) .WithXmlReferenceResolver(new XmlFileResolver(_commandLineArgumentsForCommandLine.BaseDirectory)) .WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default) - .WithStrongNameProvider(new DesktopStrongNameProvider(_commandLineArgumentsForCommandLine.KeyFileSearchPaths.WhereNotNull().ToImmutableArray())); + .WithStrongNameProvider(new DesktopStrongNameProvider(_commandLineArgumentsForCommandLine.KeyFileSearchPaths.WhereNotNull().ToImmutableArray(), Path.GetTempPath())); // Override the default documentation mode. var documentationMode = _commandLineArgumentsForCommandLine.DocumentationPath != null ? DocumentationMode.Diagnose : DocumentationMode.Parse;