From e9e05006daa026506940758120ad4349290148ae Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 28 Oct 2016 17:27:07 -0700 Subject: [PATCH] Migrating project with OutputName --- .../Rules/MigrateBuildOptionsRule.cs | 8 +++++- .../Rules/SaveOutputProjectRule.cs | 9 ++++++- .../GivenThatIWantToMigrateTestApps.cs | 27 ++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs index 78b28c2d1..b4e3510a1 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs @@ -104,6 +104,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules @"$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml", compilerOptions => compilerOptions.GenerateXmlDocumentation != null && compilerOptions.GenerateXmlDocumentation.Value); + private AddPropertyTransform AssemblyNameTransform => + new AddPropertyTransform("AssemblyName", + compilerOptions => compilerOptions.OutputName, + compilerOptions => compilerOptions.OutputName != null); + private IncludeContextTransform CompileFilesTransform => new IncludeContextTransform("Compile", transformMappings: false); @@ -171,7 +176,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules DebugTypeTransform, XmlDocTransform, XmlDocTransformFilePath, - PreserveCompilationContextTransform + PreserveCompilationContextTransform, + AssemblyNameTransform }; _propertyTransforms.AddRange(EmitEntryPointTransforms); diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/SaveOutputProjectRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/SaveOutputProjectRule.cs index ed35d9907..955295dc5 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/SaveOutputProjectRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/SaveOutputProjectRule.cs @@ -8,11 +8,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules { internal class SaveOutputProjectRule : IMigrationRule { + private static string GetContainingFolderName(string projectDirectory) + { + projectDirectory = projectDirectory.TrimEnd(new char[] { '/', '\\' }); + return Path.GetFileName(projectDirectory); + } + public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs) { var outputName = migrationRuleInputs.DefaultProjectContext.GetProjectName(); - var outputProject = Path.Combine(migrationSettings.OutputDirectory, outputName + ".csproj"); + string csprojName = $"{GetContainingFolderName(migrationSettings.ProjectDirectory)}.csproj"; + var outputProject = Path.Combine(migrationSettings.OutputDirectory, csprojName); migrationRuleInputs.OutputMSBuildProject.Save(outputProject); } diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index 5b7a78b6c..02e1b50e6 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -390,6 +390,31 @@ namespace Microsoft.DotNet.Migration.Tests VerifyAllMSBuildOutputsRunnable(projectDirectory); } + [Fact] + public void It_migrates_project_with_output_name() + { + string projectName = "AppWithOutputAssemblyName"; + string expectedOutputName = "MyApp"; + + var projectDirectory = TestAssetsManager.CreateTestInstance(projectName, callingMethod: $"It_migrates_{projectName}") + .WithLockFiles() + .Path; + + string expectedCsprojPath = Path.Combine(projectDirectory, $"{projectName}.csproj"); + if (File.Exists(expectedCsprojPath)) + { + File.Delete(expectedCsprojPath); + } + + CleanBinObj(projectDirectory); + MigrateProject(projectDirectory); + File.Exists(expectedCsprojPath).Should().BeTrue(); + Restore(projectDirectory, projectName); + BuildMSBuild(projectDirectory, projectName); + Directory.EnumerateFiles(Path.Combine(projectDirectory, "bin"), $"{expectedOutputName}.pdb", SearchOption.AllDirectories) + .Count().Should().Be(1); + } + private void VerifyAutoInjectedDesktopReferences(string projectDirectory, string projectName, bool shouldBePresent) { if (projectName != null) @@ -536,7 +561,7 @@ namespace Microsoft.DotNet.Migration.Tests result.Should().Pass(); } - private void MigrateProject(string[] migrateArgs) + private void MigrateProject(params string[] migrateArgs) { var result = MigrateCommand.Run(migrateArgs);