Merge pull request #4536 from krwq/outputNameIssue
Migrating project with OutputName
This commit is contained in:
commit
22a5a15ba9
3 changed files with 41 additions and 3 deletions
|
@ -104,6 +104,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
@"$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml",
|
@"$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml",
|
||||||
compilerOptions => compilerOptions.GenerateXmlDocumentation != null && compilerOptions.GenerateXmlDocumentation.Value);
|
compilerOptions => compilerOptions.GenerateXmlDocumentation != null && compilerOptions.GenerateXmlDocumentation.Value);
|
||||||
|
|
||||||
|
private AddPropertyTransform<CommonCompilerOptions> AssemblyNameTransform =>
|
||||||
|
new AddPropertyTransform<CommonCompilerOptions>("AssemblyName",
|
||||||
|
compilerOptions => compilerOptions.OutputName,
|
||||||
|
compilerOptions => compilerOptions.OutputName != null);
|
||||||
|
|
||||||
private IncludeContextTransform CompileFilesTransform =>
|
private IncludeContextTransform CompileFilesTransform =>
|
||||||
new IncludeContextTransform("Compile", transformMappings: false);
|
new IncludeContextTransform("Compile", transformMappings: false);
|
||||||
|
|
||||||
|
@ -171,7 +176,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
DebugTypeTransform,
|
DebugTypeTransform,
|
||||||
XmlDocTransform,
|
XmlDocTransform,
|
||||||
XmlDocTransformFilePath,
|
XmlDocTransformFilePath,
|
||||||
PreserveCompilationContextTransform
|
PreserveCompilationContextTransform,
|
||||||
|
AssemblyNameTransform
|
||||||
};
|
};
|
||||||
|
|
||||||
_propertyTransforms.AddRange(EmitEntryPointTransforms);
|
_propertyTransforms.AddRange(EmitEntryPointTransforms);
|
||||||
|
|
|
@ -8,11 +8,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
{
|
{
|
||||||
internal class SaveOutputProjectRule : IMigrationRule
|
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)
|
public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
|
||||||
{
|
{
|
||||||
var outputName = migrationRuleInputs.DefaultProjectContext.GetProjectName();
|
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);
|
migrationRuleInputs.OutputMSBuildProject.Save(outputProject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,6 +394,31 @@ namespace Microsoft.DotNet.Migration.Tests
|
||||||
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
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)
|
private void VerifyAutoInjectedDesktopReferences(string projectDirectory, string projectName, bool shouldBePresent)
|
||||||
{
|
{
|
||||||
if (projectName != null)
|
if (projectName != null)
|
||||||
|
@ -540,7 +565,7 @@ namespace Microsoft.DotNet.Migration.Tests
|
||||||
result.Should().Pass();
|
result.Should().Pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MigrateProject(string[] migrateArgs)
|
private void MigrateProject(params string[] migrateArgs)
|
||||||
{
|
{
|
||||||
var result =
|
var result =
|
||||||
MigrateCommand.Run(migrateArgs);
|
MigrateCommand.Run(migrateArgs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue