diff --git a/.vscode/launch.json b/.vscode/launch.json index 295ae46f02..a2d619556a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -52,8 +52,7 @@ "--fix-style", "-v", "diag", - "--check", - "-?" + "--check" ], "cwd": "${workspaceFolder}", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console diff --git a/src/MSBuild/LooseVersionAssemblyLoader.cs b/src/MSBuild/LooseVersionAssemblyLoader.cs index 4bf844d8f0..8ec7b2c5e9 100644 --- a/src/MSBuild/LooseVersionAssemblyLoader.cs +++ b/src/MSBuild/LooseVersionAssemblyLoader.cs @@ -63,7 +63,17 @@ public static void Register(string searchPath) continue; } - return LoadAndCache(context, candidatePath); + try + { + return LoadAndCache(context, candidatePath); + } + catch + { + // We were unable to load the assembly from the file path. It is likely that + // a different version of the assembly has already been loaded into the context. + // Be forgiving and attempt to load assembly by name without specifying a version. + return context.LoadFromAssemblyName(new AssemblyName(assemblyName.Name)); + } } } diff --git a/tests/CodeFormatterTests.cs b/tests/CodeFormatterTests.cs index 35789f9afd..3ad0a87748 100644 --- a/tests/CodeFormatterTests.cs +++ b/tests/CodeFormatterTests.cs @@ -15,18 +15,18 @@ namespace Microsoft.CodeAnalysis.Tools.Tests { - public class CodeFormatterTests : IClassFixture, IClassFixture + public class CodeFormatterTests : IClassFixture, IClassFixture { - private const string FormattedProjectPath = "tests/projects/for_code_formatter/formatted_project/"; + private const string FormattedProjectPath = "for_code_formatter/formatted_project/"; private const string FormattedProjectFilePath = FormattedProjectPath + "formatted_project.csproj"; - private const string FormattedSolutionFilePath = "tests/projects/for_code_formatter/formatted_solution/formatted_solution.sln"; + private const string FormattedSolutionFilePath = "for_code_formatter/formatted_solution/formatted_solution.sln"; - private const string UnformattedProjectPath = "tests/projects/for_code_formatter/unformatted_project/"; + private const string UnformattedProjectPath = "for_code_formatter/unformatted_project/"; private const string UnformattedProjectFilePath = UnformattedProjectPath + "unformatted_project.csproj"; private const string UnformattedProgramFilePath = UnformattedProjectPath + "program.cs"; - private const string UnformattedSolutionFilePath = "tests/projects/for_code_formatter/unformatted_solution/unformatted_solution.sln"; + private const string UnformattedSolutionFilePath = "for_code_formatter/unformatted_solution/unformatted_solution.sln"; - private const string FSharpProjectPath = "tests/projects/for_code_formatter/fsharp_project/"; + private const string FSharpProjectPath = "for_code_formatter/fsharp_project/"; private const string FSharpProjectFilePath = FSharpProjectPath + "fsharp_project.fsproj"; private static IEnumerable EmptyFilesList => Array.Empty(); @@ -36,11 +36,11 @@ public class CodeFormatterTests : IClassFixture, IClassFixture line.Contains("unformatted_project.AssemblyInfo.cs(1,1): Fix file encoding.")); - Assert.Contains(logLines, line => line.Contains("NETCoreApp,Version=v3.0.AssemblyAttributes.cs(1,1): Fix file encoding.")); + Assert.Contains(logLines, line => line.Contains("unformatted_project.AssemblyInfo.cs(21,53)")); + Assert.Contains(logLines, line => line.Contains("NETCoreApp,Version=v3.0.AssemblyAttributes.cs(4,126)")); } [Fact] @@ -124,7 +124,7 @@ public async Task FilesFormattedInUnformattedProjectFolder() includeGenerated: false, expectedExitCode: 0, expectedFilesFormatted: 2, - expectedFileCount: 3); + expectedFileCount: 5); } [Fact] diff --git a/tests/MSBuild/MSBuildWorkspaceFinderTests.cs b/tests/MSBuild/MSBuildWorkspaceFinderTests.cs index e50650d60c..c4ccb2dbe6 100644 --- a/tests/MSBuild/MSBuildWorkspaceFinderTests.cs +++ b/tests/MSBuild/MSBuildWorkspaceFinderTests.cs @@ -8,19 +8,19 @@ namespace Microsoft.CodeAnalysis.Tools.Tests.MSBuild { - public class MSBuildWorkspaceFinderTests : IClassFixture + public class MSBuildWorkspaceFinderTests : IClassFixture { private string SolutionPath => Environment.CurrentDirectory; - public MSBuildWorkspaceFinderTests(SolutionPathFixture solutionPathFixture) + public MSBuildWorkspaceFinderTests(TestProjectsPathFixture testProjectsPathFixture) { - solutionPathFixture.SetCurrentDirectory(); + testProjectsPathFixture.SetCurrentDirectory(); } [Fact] public void ThrowsException_CannotFindMSBuildProjectFile() { - var workspacePath = "tests/projects/for_workspace_finder/no_project_or_solution/"; + var workspacePath = "for_workspace_finder/no_project_or_solution/"; var exceptionMessageStart = string.Format( Resources.Could_not_find_a_MSBuild_project_or_solution_file_in_0_Specify_which_to_use_with_the_workspace_argument, Path.Combine(SolutionPath, workspacePath)).Replace('/', Path.DirectorySeparatorChar); @@ -31,7 +31,7 @@ public void ThrowsException_CannotFindMSBuildProjectFile() [Fact] public void ThrowsException_MultipleMSBuildProjectFiles() { - var workspacePath = "tests/projects/for_workspace_finder/multiple_projects/"; + var workspacePath = "for_workspace_finder/multiple_projects/"; var exceptionMessageStart = string.Format( Resources.Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument, Path.Combine(SolutionPath, workspacePath)).Replace('/', Path.DirectorySeparatorChar); @@ -42,7 +42,7 @@ public void ThrowsException_MultipleMSBuildProjectFiles() [Fact] public void ThrowsException_MultipleMSBuildSolutionFiles() { - var workspacePath = "tests/projects/for_workspace_finder/multiple_solutions/"; + var workspacePath = "for_workspace_finder/multiple_solutions/"; var exceptionMessageStart = string.Format( Resources.Multiple_MSBuild_solution_files_found_in_0_Specify_which_to_use_with_the_workspace_argument, Path.Combine(SolutionPath, workspacePath)).Replace('/', Path.DirectorySeparatorChar); @@ -53,7 +53,7 @@ public void ThrowsException_MultipleMSBuildSolutionFiles() [Fact] public void ThrowsException_SolutionAndProjectAmbiguity() { - var workspacePath = "tests/projects/for_workspace_finder/project_and_solution/"; + var workspacePath = "for_workspace_finder/project_and_solution/"; var exceptionMessageStart = string.Format( Resources.Both_a_MSBuild_project_file_and_solution_file_found_in_0_Specify_which_to_use_with_the_workspace_argument, Path.Combine(SolutionPath, workspacePath)).Replace('/', Path.DirectorySeparatorChar); @@ -64,7 +64,7 @@ public void ThrowsException_SolutionAndProjectAmbiguity() [Fact] public void FindsSolutionByFolder() { - const string Path = "tests/projects/for_workspace_finder/single_solution/"; + const string Path = "for_workspace_finder/single_solution/"; var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(SolutionPath, Path); @@ -76,7 +76,7 @@ public void FindsSolutionByFolder() [Fact] public void FindsSolutionByFilePath() { - const string Path = "tests/projects/for_workspace_finder/multiple_solutions/solution_b.sln"; + const string Path = "for_workspace_finder/multiple_solutions/solution_b.sln"; var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(SolutionPath, Path); @@ -88,7 +88,7 @@ public void FindsSolutionByFilePath() [Fact] public void FindsProjectByFolder() { - const string Path = "tests/projects/for_workspace_finder/single_project/"; + const string Path = "for_workspace_finder/single_project/"; var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(SolutionPath, Path); @@ -100,7 +100,7 @@ public void FindsProjectByFolder() [Fact] public void FindsProjectByFilePath() { - const string Path = "tests/projects/for_workspace_finder/multiple_projects/project_b.csproj"; + const string Path = "for_workspace_finder/multiple_projects/project_b.csproj"; var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(SolutionPath, Path); diff --git a/tests/Utilities/SolutionPathFixture.cs b/tests/Utilities/TestProjectsPathFixture.cs similarity index 83% rename from tests/Utilities/SolutionPathFixture.cs rename to tests/Utilities/TestProjectsPathFixture.cs index 271159b7d8..567424e2d5 100644 --- a/tests/Utilities/SolutionPathFixture.cs +++ b/tests/Utilities/TestProjectsPathFixture.cs @@ -7,9 +7,9 @@ namespace Microsoft.CodeAnalysis.Tools.Tests.Utilities { /// - /// This test fixture sets the to the dotnet-format solution's path. + /// This test fixture sets the to the dotnet-format test projects folder path. /// - public class SolutionPathFixture : IDisposable + public class TestProjectsPathFixture : IDisposable { private static int s_registered = 0; private static string s_currentDirectory; @@ -20,7 +20,7 @@ public void SetCurrentDirectory() { s_currentDirectory = Environment.CurrentDirectory; var solutionPath = Directory.GetParent(s_currentDirectory).Parent.Parent.Parent.Parent.FullName; - Environment.CurrentDirectory = solutionPath; + Environment.CurrentDirectory = Path.Combine(solutionPath, "tests", "projects"); } } diff --git a/tests/projects/Directory.Build.props b/tests/projects/Directory.Build.props new file mode 100644 index 0000000000..1cd50ce64f --- /dev/null +++ b/tests/projects/Directory.Build.props @@ -0,0 +1,4 @@ + + + + diff --git a/tests/projects/Directory.Build.targets b/tests/projects/Directory.Build.targets new file mode 100644 index 0000000000..8f68664271 --- /dev/null +++ b/tests/projects/Directory.Build.targets @@ -0,0 +1,4 @@ + + + + diff --git a/tests/projects/for_code_formatter/unformatted_project/.editorconfig b/tests/projects/for_code_formatter/unformatted_project/.editorconfig index 8b5bebcf12..68704aa414 100644 --- a/tests/projects/for_code_formatter/unformatted_project/.editorconfig +++ b/tests/projects/for_code_formatter/unformatted_project/.editorconfig @@ -2,7 +2,7 @@ root = true # C# files -[{Program.cs,other_items/*.cs}] +[{Program.cs,other_items/*.cs,obj/**/*.cs}] #### Core EditorConfig Options ####