Emitting PackageId whenever we emit AssemblyName. We need to do this to preserve the behavior from PJ where the package id matched the containing PJ folder name. In MSBuild, PackageId will match AssemblyName, unless it is explicitly specified. (#4990)
This commit is contained in:
parent
8eaec8715b
commit
bd590f51e6
4 changed files with 79 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Build.Construction;
|
||||
using Microsoft.DotNet.ProjectJsonMigration.Transforms;
|
||||
|
@ -103,6 +104,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
compilerOptions => compilerOptions.OutputName,
|
||||
compilerOptions => compilerOptions.OutputName != null);
|
||||
|
||||
private Func<string, AddPropertyTransform<CommonCompilerOptions>> PackageIdTransformExecute =>
|
||||
(projectFolderName) =>
|
||||
new AddPropertyTransform<CommonCompilerOptions>("PackageId",
|
||||
compilerOptions => projectFolderName,
|
||||
compilerOptions => compilerOptions.OutputName != null);
|
||||
|
||||
private IncludeContextTransform CompileFilesTransform =>
|
||||
new IncludeContextTransform("Compile", transformMappings: false);
|
||||
|
||||
|
@ -202,6 +209,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
|
||||
var compilerOptions = projectContext.ProjectFile.GetCompilerOptions(null, null);
|
||||
|
||||
var projectDirectoryName = new DirectoryInfo(migrationSettings.ProjectDirectory).Name;
|
||||
_propertyTransforms.Add(PackageIdTransformExecute(projectDirectoryName));
|
||||
|
||||
var project = migrationRuleInputs.DefaultProjectContext.ProjectFile;
|
||||
var projectType = project.GetProjectType();
|
||||
|
||||
|
|
|
@ -84,6 +84,36 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
mockProj.Items.Count().Should().Be(0);
|
||||
}
|
||||
|
||||
public void MigratingOutputNamePopulatesAssemblyName()
|
||||
{
|
||||
var mockProj = RunBuildOptionsRuleOnPj(@"
|
||||
{
|
||||
""buildOptions"": {
|
||||
""outputName"": ""some name""
|
||||
}
|
||||
}");
|
||||
|
||||
mockProj.Properties.Count(p => p.Name == "AssemblyName").Should().Be(1);
|
||||
mockProj.Properties.First(p => p.Name == "AssemblyName").Value.Should().Be("some name");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MigratingOutputNamePopulatesPackageIdWithTheProjectContainingFolderName()
|
||||
{
|
||||
var testDirectoryPath = Temp.CreateDirectory().Path;
|
||||
var testDirectoryName = new DirectoryInfo(testDirectoryPath).Name;
|
||||
var mockProj = RunBuildOptionsRuleOnPj(@"
|
||||
{
|
||||
""buildOptions"": {
|
||||
""outputName"": ""some name""
|
||||
}
|
||||
}",
|
||||
testDirectoryPath);
|
||||
|
||||
mockProj.Properties.Count(p => p.Name == "PackageId").Should().Be(1);
|
||||
mockProj.Properties.First(p => p.Name == "PackageId").Value.Should().Be(testDirectoryName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MigratingEmitEntryPointTruePopulatesOutputTypeField()
|
||||
{
|
||||
|
|
|
@ -107,6 +107,12 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
return base.Execute(args);
|
||||
}
|
||||
|
||||
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
||||
{
|
||||
args = $"pack {BuildArgs()} {args}";
|
||||
return base.ExecuteWithCapturedOutput(args);
|
||||
}
|
||||
|
||||
private string BuildArgs()
|
||||
{
|
||||
return $"{_projectPath} {OutputOption} {BuildBasePathOption} {TempOutputOption} {ConfigurationOption} {VersionSuffixOption} {ServiceableOption}";
|
||||
|
|
|
@ -434,7 +434,17 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
File.Exists(expectedCsprojPath).Should().BeTrue();
|
||||
Restore(projectDirectory, projectName);
|
||||
BuildMSBuild(projectDirectory, projectName);
|
||||
Directory.EnumerateFiles(Path.Combine(projectDirectory, "bin"), $"{expectedOutputName}.pdb", SearchOption.AllDirectories)
|
||||
Directory.EnumerateFiles(
|
||||
Path.Combine(projectDirectory, "bin"),
|
||||
$"{expectedOutputName}.pdb",
|
||||
SearchOption.AllDirectories)
|
||||
.Count().Should().Be(1);
|
||||
|
||||
PackMSBuild(projectDirectory, projectName);
|
||||
Directory.EnumerateFiles(
|
||||
Path.Combine(projectDirectory, "bin"),
|
||||
$"{projectName}.1.0.0.nupkg",
|
||||
SearchOption.AllDirectories)
|
||||
.Count().Should().Be(1);
|
||||
}
|
||||
|
||||
|
@ -465,7 +475,7 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void It_migrates_sln()
|
||||
public void ItMigratesSln()
|
||||
{
|
||||
var rootDirectory = TestAssetsManager.CreateTestInstance(
|
||||
"TestAppWithSlnAndMultipleProjects",
|
||||
|
@ -709,7 +719,11 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
return result.StdOut;
|
||||
}
|
||||
|
||||
private string PublishMSBuild(string projectDirectory, string projectName, string runtime, string configuration = "Debug")
|
||||
private string PublishMSBuild(
|
||||
string projectDirectory,
|
||||
string projectName,
|
||||
string runtime,
|
||||
string configuration = "Debug")
|
||||
{
|
||||
if (projectName != null)
|
||||
{
|
||||
|
@ -728,6 +742,22 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
return result.StdOut;
|
||||
}
|
||||
|
||||
private string PackMSBuild(string projectDirectory, string projectName)
|
||||
{
|
||||
if (projectName != null && !Path.HasExtension(projectName))
|
||||
{
|
||||
projectName = projectName + ".csproj";
|
||||
}
|
||||
|
||||
var result = new PackCommand()
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
.ExecuteWithCapturedOutput($"{projectName}");
|
||||
|
||||
result.Should().Pass();
|
||||
|
||||
return result.StdOut;
|
||||
}
|
||||
|
||||
private void DeleteXproj(string projectDirectory)
|
||||
{
|
||||
var xprojFiles = Directory.EnumerateFiles(projectDirectory, "*.xproj");
|
||||
|
|
Loading…
Reference in a new issue