Skip to content

Commit

Permalink
Revert "Fix issue with CentralPackageVersions logging error when usin…
Browse files Browse the repository at this point in the history
…g a custom import pattern" (#327)

* Revert "Fix issue with CentralPackageVersions logging error when using a custom import pattern. (#325)"

This reverts commit 99a3dc3.

* Revert "Log an error if imported in Directory.Build.props (#322)"

This reverts commit af63eab.

Reopens #324 and #179
  • Loading branch information
jeffkl committed Dec 3, 2021
1 parent 99a3dc3 commit 27d7541
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,37 +236,6 @@ public void IsDisabledForProjectsWithPackagesConfigOrDoNotSupportPackageReferenc
enableCentralPackageVersions.ShouldBe("false");
}

[Fact]
public void LogErrorIfImportedInDirectoryBuildProps()
{
ProjectCreator.Create()
.Import(Path.Combine(ThisAssemblyDirectory, @"Sdk\Sdk.props"))
.Import(Path.Combine(ThisAssemblyDirectory, @"Sdk\Sdk.targets"))
.Save(GetTempFile("Directory.Build.props"));

ProjectCreator.Create()
.Save(GetTempFile("Directory.Build.targets"));

ProjectCreator.Templates
.PackagesProps(
path: GetTempFile("Packages.props"),
packageReferences: new Dictionary<string, string>
{
["Foo"] = "1.2.3",
})
.Save();

ProjectCreator.Templates
.SdkCsproj(projectCreator: creator => creator
.ItemPackageReference("Foo"))
.Save(GetTempFile("Test.csproj"))
.TryBuild("CheckPackageReferences", out bool result, out BuildOutput buildOutput);

result.ShouldBeFalse(buildOutput.GetConsoleLog());

buildOutput.Errors.ShouldBe(new[] { "Microsoft.Build.CentralPackageVersions was not imported in Directory.Build.targets. See https://github.com/microsoft/MSBuildSdks/tree/main/src/CentralPackageVersions for more information on how to include this SDK." }, buildOutput.GetConsoleLog());
}

[Theory]
[InlineData(".csproj")]
[InlineData(".fsproj")]
Expand Down Expand Up @@ -496,44 +465,15 @@ public void VersionOverridesWithoutCentralVersionsCanBeDisabled(string projectFi
buildOutput.Errors.ShouldBe(new[] { $"The package reference \'Orphan\' must have a version defined in \'{packagesProps.FullPath}\'." });
}

[Fact]
public void WorksWithCustomImportPattern()
private ProjectCreator WritePackagesProps()
{
WritePackagesProps(writeDirectoryBuildPropsTargets: false);

ProjectCreator customProps = ProjectCreator.Create()
.ImportSdk("Sdk.props", "Microsoft.NET.Sdk")
.Save(Path.Combine(TestRootPath, "Custom.props"));
ProjectCreator.Create()
.Save(Path.Combine(TestRootPath, "Directory.Build.props"));

ProjectCreator customTargets = ProjectCreator.Create()
.ImportSdk("Sdk.targets", "Microsoft.NET.Sdk")
ProjectCreator.Create()
.Import(Path.Combine(ThisAssemblyDirectory, @"Sdk\Sdk.props"))
.Import(Path.Combine(ThisAssemblyDirectory, @"Sdk\Sdk.targets"))
.Save(Path.Combine(TestRootPath, "Custom.targets"));

ProjectCreator.Create()
.Import(customProps)
.Property("TargetFramework", "net45")
.ItemPackageReference("Foo")
.Import(customTargets)
.Save(GetTempFileWithExtension(".csproj"))
.TryBuild("CheckPackageReferences", out bool result, out BuildOutput buildOutput);

result.ShouldBeTrue(buildOutput.GetConsoleLog());
}

private ProjectCreator WritePackagesProps(bool writeDirectoryBuildPropsTargets = true)
{
if (writeDirectoryBuildPropsTargets)
{
ProjectCreator.Create()
.Save(Path.Combine(TestRootPath, "Directory.Build.props"));

ProjectCreator.Create()
.Import(Path.Combine(ThisAssemblyDirectory, @"Sdk\Sdk.props"))
.Import(Path.Combine(ThisAssemblyDirectory, @"Sdk\Sdk.targets"))
.Save(Path.Combine(TestRootPath, "Directory.Build.targets"));
}
.Save(Path.Combine(TestRootPath, "Directory.Build.targets"));

return ProjectCreator.Templates
.PackagesProps(
Expand Down
2 changes: 2 additions & 0 deletions src/CentralPackageVersions/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
<UsingMicrosoftCentralPackageVersionsSdk>true</UsingMicrosoftCentralPackageVersionsSdk>
</PropertyGroup>

<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition=" '$(MicrosoftCommonPropsHasBeenImported)' != 'true' And Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props') "/>

<Import Project="$(CustomAfterCentralPackageVersionsProps)" Condition=" '$(CustomAfterCentralPackageVersionsProps)' != '' And Exists('$(CustomAfterCentralPackageVersionsProps)') " />
</Project>
12 changes: 1 addition & 11 deletions src/CentralPackageVersions/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
Condition=" '$(EnableCentralPackageVersions)' != 'false' And '$(CustomBeforeCentralPackageVersionsTargets)' != '' And Exists('$(CustomBeforeCentralPackageVersionsTargets)') " />

<PropertyGroup Condition=" '$(EnableCentralPackageVersions)' != 'false' ">
<!--
Keep track if this file was imported before Directory.Build.targets
-->
<_WasMicrosoftCentralPackageVersionsSdkImportedInDirectoryBuildTargets Condition="'$(_WasMicrosoftCentralPackageVersionsSdkImportedInDirectoryBuildTargets)' == '' And '$(CommonTargetsPath)' == ''">false</_WasMicrosoftCentralPackageVersionsSdkImportedInDirectoryBuildTargets>
<!--
Walk up the directory tree looking for a Packages.props, unless a user has already specified a path.
-->
Expand Down Expand Up @@ -155,13 +151,7 @@
<_DuplicateGlobalPackageReference Include="@(_OriginalPackageReference)"
Condition=" '@(GlobalPackageReference)' == '@(_OriginalPackageReference)' and '%(Identity)' != '' " />
</ItemGroup>

<!--
Log an error if this was imported before Directory.Build.targets
-->
<Error Text="Microsoft.Build.CentralPackageVersions was not imported in Directory.Build.targets. See https://github.com/microsoft/MSBuildSdks/tree/main/src/CentralPackageVersions for more information on how to include this SDK."
Condition="'$(_WasMicrosoftCentralPackageVersionsSdkImportedInDirectoryBuildTargets)' == 'false'"
File="$(MSBuildProjectFullPath)" />

<!--
Log an error if there are any duplicate <PackageReference /> items where a <GlobalPackageReference /> is already defined.
-->
Expand Down

0 comments on commit 27d7541

Please sign in to comment.