Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix output path issues with customized builds #3270

Merged
merged 4 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<IsInnerBuild Condition="'$(TargetFramework)' != '' AND '$(TargetFrameworks)' != ''">true</IsInnerBuild>
<SymbolPackageFormat Condition="'$(SymbolPackageFormat)' == ''">symbols.nupkg</SymbolPackageFormat>
<AddPriFileDependsOn Condition="'$(MicrosoftPortableCurrentVersionPropsHasBeenImported)' == 'true'">DeterminePortableBuildCapabilities</AddPriFileDependsOn>
<NuspecOutputPath Condition="'$(NuspecOutputPath)' == ''">$(BaseIntermediateOutputPath)$(Configuration)\</NuspecOutputPath>
<WarnOnPackingNonPackableProject Condition="'$(WarnOnPackingNonPackableProject)' == ''">false</WarnOnPackingNonPackableProject>
<ImportNuGetBuildTasksPackTargetsFromSdk Condition="'$(ImportNuGetBuildTasksPackTargetsFromSdk)' == ''">false</ImportNuGetBuildTasksPackTargetsFromSdk>
<AllowedOutputExtensionsInPackageBuildOutputFolder>.dll; .exe; .winmd; .json; .pri; .xml; $(AllowedOutputExtensionsInPackageBuildOutputFolder)</AllowedOutputExtensionsInPackageBuildOutputFolder>
Expand All @@ -70,8 +69,22 @@ Copyright (c) .NET Foundation. All rights reserved.
</BuildOutputInPackage>
</ItemDefinitionGroup>

<Target Name="_GetOutputItemsFromPack"
Returns="@(_OutputPackItems)">
<PropertyGroup>
<RestoreOutputPath Condition="'$(RestoreOutputPath)' == ''">$(MSBuildProjectExtensionsPath)</RestoreOutputPath>
<PackageOutputPath Condition="'$(PackageOutputPath)' == ''">$(BaseOutputPath)$(Configuration)\</PackageOutputPath>
Nirmal4G marked this conversation as resolved.
Show resolved Hide resolved
<NuspecOutputPath Condition="'$(NuspecOutputPath)' == ''">$(BaseIntermediateOutputPath)$(Configuration)\</NuspecOutputPath>
</PropertyGroup>

<!--
============================================================
_GetAbsoluteOutputPathsForPack
Gets the absolute output paths for Pack.
============================================================
-->
<Target Name="_GetAbsoluteOutputPathsForPack">
<ConvertToAbsolutePath Paths="$(RestoreOutputPath)">
Nirmal4G marked this conversation as resolved.
Show resolved Hide resolved
<Output TaskParameter="AbsolutePaths" PropertyName="RestoreOutputAbsolutePath" />
</ConvertToAbsolutePath>

<ConvertToAbsolutePath Paths="$(PackageOutputPath)">
<Output TaskParameter="AbsolutePaths" PropertyName="PackageOutputAbsolutePath" />
Expand All @@ -80,6 +93,19 @@ Copyright (c) .NET Foundation. All rights reserved.
<ConvertToAbsolutePath Paths="$(NuspecOutputPath)">
<Output TaskParameter="AbsolutePaths" PropertyName="NuspecOutputAbsolutePath" />
</ConvertToAbsolutePath>
</Target>

<!--
============================================================
_GetOutputItemsFromPack
Gets the output '.nupkg' and '.nuspec' absolute file paths.
============================================================
-->
<Target Name="_GetOutputItemsFromPack"
DependsOnTargets="_GetAbsoluteOutputPathsForPack"
Returns="@(_OutputPackItems)">

<!-- 'PackageOutputAbsolutePath' and 'NuspecOutputAbsolutePath' will be provided by '_GetAbsoluteOutputPathsForPack' target -->

<GetPackOutputItemsTask
PackageOutputPath="$(PackageOutputAbsolutePath)"
Expand Down Expand Up @@ -153,23 +179,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<PropertyGroup Condition="$(ContinuePackingAfterGeneratingNuspec) == '' ">
<ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>
<PropertyGroup>
<PackageOutputPath Condition=" '$(PackageOutputPath)' == '' ">$(OutputPath)</PackageOutputPath>
<RestoreOutputPath Condition=" '$(RestoreOutputPath)' == '' " >$(MSBuildProjectExtensionsPath)</RestoreOutputPath>
</PropertyGroup>

<ConvertToAbsolutePath Paths="$(NuspecOutputPath)">
<Output TaskParameter="AbsolutePaths" PropertyName="NuspecOutputAbsolutePath" />
</ConvertToAbsolutePath>
<ConvertToAbsolutePath Paths="$(RestoreOutputPath)">
<Output TaskParameter="AbsolutePaths" PropertyName="RestoreOutputAbsolutePath" />
</ConvertToAbsolutePath>
<ConvertToAbsolutePath Paths="$(PackageOutputPath)">
<Output TaskParameter="AbsolutePaths" PropertyName="PackageOutputAbsolutePath" />
</ConvertToAbsolutePath>
<ConvertToAbsolutePath Condition="$(NuspecFile) != ''" Paths="$(NuspecFile)">
<Output TaskParameter="AbsolutePaths" PropertyName="NuspecFileAbsolutePath" />
</ConvertToAbsolutePath>

<ItemGroup>
<!--This catches changes to properties-->
Expand Down Expand Up @@ -203,6 +212,11 @@ Copyright (c) .NET Foundation. All rights reserved.
Condition="$(IsPackable) == 'true'"
Inputs="@(NuGetPackInput)" Outputs="@(NuGetPackOutput)"
DependsOnTargets="$(GenerateNuspecDependsOn);_CalculateInputsOutputsForPack;_GetProjectReferenceVersions;_InitializeNuspecRepositoryInformationProperties">

<ConvertToAbsolutePath Condition="$(NuspecFile) != ''" Paths="$(NuspecFile)">
<Output TaskParameter="AbsolutePaths" PropertyName="NuspecFileAbsolutePath" />
</ConvertToAbsolutePath>

<!-- Call Pack -->
<PackTask PackItem="$(PackProjectInputFile)"
PackageFiles="@(_PackageFiles)"
Expand Down Expand Up @@ -294,10 +308,9 @@ Copyright (c) .NET Foundation. All rights reserved.

Nirmal4G marked this conversation as resolved.
Show resolved Hide resolved
<Target Name="_GetProjectReferenceVersions"
Condition="'$(NuspecFile)' == ''"
DependsOnTargets="_CalculateInputsOutputsForPack;$(GetPackageVersionDependsOn)">
<ConvertToAbsolutePath Paths="$(RestoreOutputPath)">
<Output TaskParameter="AbsolutePaths" PropertyName="RestoreOutputAbsolutePath" />
</ConvertToAbsolutePath>
DependsOnTargets="_GetAbsoluteOutputPathsForPack;$(GetPackageVersionDependsOn)">

<!-- 'RestoreOutputAbsolutePath' will be provided by '_GetAbsoluteOutputPathsForPack' target -->

<ConvertToAbsolutePath Condition="'$(ProjectAssetsFile)' != ''" Paths="$(ProjectAssetsFile)">
<Output TaskParameter="AbsolutePaths" PropertyName="ProjectAssetsFileAbsolutePath" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6070,7 +6070,6 @@ public void PackCommand_ProjectFile_PackageIconUrl_WithNuspec_WithPackTask_Warns
<OutputPath>out</OutputPath>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<PackageIconUrl>https://test/icon.jpg</PackageIconUrl>
<PackageOutputPath>bin\Debug\</PackageOutputPath>
nkolev92 marked this conversation as resolved.
Show resolved Hide resolved
<Authors>Alice</Authors>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,194 @@ public PackCommandTests(MsbuildIntegrationTestFixture fixture)
msbuildFixture = fixture;
}

[PlatformFact(Platform.Windows)]
public void PackCommand_NewProject_OutputsInDefaultPaths()
{
// Arrange
using (var testDirectory = TestDirectory.Create())
{
var projectName = "ClassLibrary1";
var workingDirectory = Path.Combine(testDirectory, projectName);
var nupkgPath = Path.Combine(workingDirectory, @"bin\Debug", $"{projectName}.1.0.0.nupkg");
var nuspecPath = Path.Combine(workingDirectory, @"obj\Debug", $"{projectName}.1.0.0.nuspec");

// Act
msbuildFixture.CreateDotnetNewProject(testDirectory.Path, projectName, "classlib");
msbuildFixture.PackProject(workingDirectory, projectName, string.Empty, null);

// Assert
Assert.True(File.Exists(nupkgPath), "The output .nupkg is not in the default place");
Assert.True(File.Exists(nuspecPath), "The intermediate nuspec file is not in the default place");
}
}

[PlatformFact(Platform.Windows)]
public void PackCommand_NewProject_ContinuousOutputInBothDefaultAndCustomPaths()
{
// Arrange
using (var testDirectory = TestDirectory.Create())
{
var projectName = "ClassLibrary1";
var workingDirectory = Path.Combine(testDirectory, projectName);

msbuildFixture.CreateDotnetNewProject(testDirectory.Path, projectName, "classlib");
msbuildFixture.RestoreProject(workingDirectory, projectName, string.Empty);
msbuildFixture.BuildProject(workingDirectory, projectName, string.Empty);

// With default output path
var nupkgPath = Path.Combine(workingDirectory, @"bin\Debug", $"{projectName}.1.0.0.nupkg");
var nuspecPath = Path.Combine(workingDirectory, @"obj\Debug", $"{projectName}.1.0.0.nuspec");

// Act
msbuildFixture.PackProject(workingDirectory, projectName, "--no-build", null);

// Assert
Assert.True(File.Exists(nupkgPath), "The output .nupkg is not in the default place");
Assert.True(File.Exists(nuspecPath), "The intermediate nuspec file is not in the default place");

// With custom output path
var publishDir = Path.Combine(workingDirectory, "publish");
nupkgPath = Path.Combine(publishDir, $"{projectName}.1.0.0.nupkg");
nuspecPath = Path.Combine(publishDir, $"{projectName}.1.0.0.nuspec");

// Act
msbuildFixture.PackProject(workingDirectory, projectName, $"--no-build -o {publishDir}", publishDir);

// Assert
Assert.True(File.Exists(nupkgPath), "The output .nupkg is not in the expected place");
Assert.True(File.Exists(nuspecPath), "The intermediate nuspec file is not in the expected place");
}
}

[PlatformFact(Platform.Windows)]
public void PackCommand_NewSolution_OutputInDefaultPaths()
{
// Arrange
using (var testDirectory = TestDirectory.Create())
{
var solutionName = "Solution1";
var projectName = "ClassLibrary1";
var referencedProject1 = "ClassLibrary2";
var referencedProject2 = "ClassLibrary3";

var projectAndReference1Folder = "Src";
var reference2Folder = "src";

var projectFolder = Path.Combine(testDirectory.Path, projectAndReference1Folder, projectName);

var projectFileRelativ = Path.Combine(projectAndReference1Folder, projectName, $"{projectName}.csproj");
var referencedProject1RelativDir = Path.Combine(projectAndReference1Folder, referencedProject1, $"{referencedProject1}.csproj");
var referencedProject2RelativDir = Path.Combine(reference2Folder, referencedProject2, $"{referencedProject2}.csproj");

msbuildFixture.CreateDotnetNewProject(Path.Combine(testDirectory.Path, projectAndReference1Folder), projectName, "classlib");
msbuildFixture.CreateDotnetNewProject(Path.Combine(testDirectory.Path, projectAndReference1Folder), referencedProject1, "classlib");
msbuildFixture.CreateDotnetNewProject(Path.Combine(testDirectory.Path, reference2Folder), referencedProject2, "classlib");

msbuildFixture.RunDotnet(testDirectory.Path, $"new solution -n {solutionName}");
msbuildFixture.RunDotnet(testDirectory.Path, $"sln {solutionName}.sln add {projectFileRelativ}");
msbuildFixture.RunDotnet(testDirectory.Path, $"sln {solutionName}.sln add {referencedProject1RelativDir}");
msbuildFixture.RunDotnet(testDirectory.Path, $"sln {solutionName}.sln add {referencedProject2RelativDir}");

var projectFile = Path.Combine(testDirectory.Path, projectFileRelativ);
using (var stream = new FileStream(projectFile, FileMode.Open, FileAccess.ReadWrite))
{
var xml = XDocument.Load(stream);
var attributes = new Dictionary<string, string>();
var properties = new Dictionary<string, string>();

ProjectFileUtils.AddItem(xml, "ProjectReference", @"..\ClassLibrary2\ClassLibrary2.csproj", string.Empty, properties, attributes);
ProjectFileUtils.AddItem(xml, "ProjectReference", @"..\ClassLibrary3\ClassLibrary3.csproj", string.Empty, properties, attributes);

ProjectFileUtils.WriteXmlToFile(xml, stream);
}

msbuildFixture.RestoreSolution(testDirectory, solutionName, string.Empty);

var nupkgPath = Path.Combine(projectFolder, @"bin\Debug", $"{projectName}.1.0.0.nupkg");
var nuspecPath = Path.Combine(projectFolder, @"obj\Debug", $"{projectName}.1.0.0.nuspec");

// Act
msbuildFixture.PackSolution(testDirectory, solutionName, string.Empty, null);

// Assert
Assert.True(File.Exists(nupkgPath), "The output .nupkg is not in the default place");
Assert.True(File.Exists(nuspecPath), "The intermediate nuspec file is not in the default place");
}
}

[PlatformFact(Platform.Windows)]
public void PackCommand_NewSolution_ContinuousOutputInBothDefaultAndCustomPaths()
Nirmal4G marked this conversation as resolved.
Show resolved Hide resolved
{
// Arrange
using (var testDirectory = TestDirectory.Create())
{
var solutionName = "Solution1";
var projectName = "ClassLibrary1";
var referencedProject1 = "ClassLibrary2";
var referencedProject2 = "ClassLibrary3";

var projectAndReference1Folder = "Src";
var reference2Folder = "src";

var projectFolder = Path.Combine(testDirectory.Path, projectAndReference1Folder, projectName);

var projectFileRelativ = Path.Combine(projectAndReference1Folder, projectName, $"{projectName}.csproj");
var referencedProject1RelativDir = Path.Combine(projectAndReference1Folder, referencedProject1, $"{referencedProject1}.csproj");
var referencedProject2RelativDir = Path.Combine(reference2Folder, referencedProject2, $"{referencedProject2}.csproj");

msbuildFixture.CreateDotnetNewProject(Path.Combine(testDirectory.Path, projectAndReference1Folder), projectName, "classlib");
msbuildFixture.CreateDotnetNewProject(Path.Combine(testDirectory.Path, projectAndReference1Folder), referencedProject1, "classlib");
msbuildFixture.CreateDotnetNewProject(Path.Combine(testDirectory.Path, reference2Folder), referencedProject2, "classlib");

msbuildFixture.RunDotnet(testDirectory.Path, $"new solution -n {solutionName}");
msbuildFixture.RunDotnet(testDirectory.Path, $"sln {solutionName}.sln add {projectFileRelativ}");
msbuildFixture.RunDotnet(testDirectory.Path, $"sln {solutionName}.sln add {referencedProject1RelativDir}");
msbuildFixture.RunDotnet(testDirectory.Path, $"sln {solutionName}.sln add {referencedProject2RelativDir}");

var projectFile = Path.Combine(testDirectory.Path, projectFileRelativ);
using (var stream = new FileStream(projectFile, FileMode.Open, FileAccess.ReadWrite))
{
var xml = XDocument.Load(stream);
var attributes = new Dictionary<string, string>();
var properties = new Dictionary<string, string>();

ProjectFileUtils.AddItem(xml, "ProjectReference", @"..\ClassLibrary2\ClassLibrary2.csproj", string.Empty, properties, attributes);
ProjectFileUtils.AddItem(xml, "ProjectReference", @"..\ClassLibrary3\ClassLibrary3.csproj", string.Empty, properties, attributes);

ProjectFileUtils.WriteXmlToFile(xml, stream);
}

msbuildFixture.RestoreSolution(testDirectory, solutionName, string.Empty);
msbuildFixture.BuildSolution(testDirectory, solutionName, string.Empty);

// With default output path within project folder

// Arrange
var nupkgPath = Path.Combine(projectFolder, @"bin\Debug", $"{projectName}.1.0.0.nupkg");
var nuspecPath = Path.Combine(projectFolder, @"obj\Debug", $"{projectName}.1.0.0.nuspec");

// Act
msbuildFixture.PackSolution(testDirectory, solutionName, "--no-build", null);

// Assert
Assert.True(File.Exists(nupkgPath), "The output .nupkg is not in the default place");
Assert.True(File.Exists(nuspecPath), "The intermediate nuspec file is not in the default place");

// With common publish path within solution folder

// Arrange
var publishDir = Path.Combine(testDirectory.Path, "publish");
nupkgPath = Path.Combine(publishDir, $"{projectName}.1.0.0.nupkg");
nuspecPath = Path.Combine(publishDir, $"{projectName}.1.0.0.nuspec");

msbuildFixture.PackSolution(testDirectory, solutionName, $"--no-build -o {publishDir}", publishDir);

// Assert
Assert.True(File.Exists(nupkgPath), "The output .nupkg is not in the expected place");
Assert.True(File.Exists(nuspecPath), "The intermediate nuspec file is not in the expected place");
}
}

[PlatformFact(Platform.Windows)]
public void PackCommand_PackNewDefaultProject_NupkgExists()
{
Expand Down Expand Up @@ -4374,7 +4562,6 @@ public void PackCommand_PackIcon_WithNuspec_IconUrl_Warns_Succeeds()
projectBuilder
.WithProjectName("test")
.WithProperty("Authors", "Alice")
.WithProperty("PackageOutputPath", "bin\\Debug\\")
.WithProperty("NuspecFile", "test.nuspec")
.WithPackageIconUrl("https://test/icon.jpg");

Expand Down