Skip to content

Commit

Permalink
Disable target framework validation in NoTargets
Browse files Browse the repository at this point in the history
Since NoTargets projects don't define runtime requirements like target framework, there is no point in checking compatibility.

Fixes microsoft#191
  • Loading branch information
jeffkl committed Jul 14, 2020
1 parent 5ab9834 commit 93ca4c3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/NoTargets.UnitTests/NoTargetsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ namespace Microsoft.Build.NoTargets.UnitTests
{
public class NoTargetsTests : MSBuildSdkTestBase
{
[Fact]
public void DoNotReferenceOutputAssemblies()
{
ProjectCreator projectA = ProjectCreator.Templates.SdkCsproj(
path: Path.Combine(TestRootPath, "ProjectA", "ProjectA.csproj"),
targetFramework: "netcoreapp2.1")
.Save();

ProjectCreator noTargetsProject = ProjectCreator.Templates.NoTargetsProject(
path: Path.Combine(TestRootPath, "NoTargets", "NoTargets.csproj"),
targetFramework: "net45")
.ItemProjectReference(projectA)
.Save();

noTargetsProject.TryRestore(out bool result, out BuildOutput buildOutput);

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

[Fact]
public void EnableDefaultCompileItemsIsFalse()
{
Expand Down
16 changes: 16 additions & 0 deletions src/NoTargets/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,24 @@
<!-- Disable default Compile and EmbeddedResource items for NoTargets projects -->
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>

<!--
NuGet should always restore Traversal projects with "PackageReference" style restore. Setting this property will cause the right thing to happen even if there aren't any PackageReference items in the project.
-->
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>

<ItemDefinitionGroup Condition=" '$(NoTargetsDoNotReferenceOutputAssemblies)' != 'false' ">
<ProjectReference>
<!--
Setting ReferenceOutputAssembly skips target framework cross-project validation in NuGet. Since NoTargets projects don't define runtime
constraints like a target framework, there's no point in checking the compatibilty of project references.
-->
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
</ProjectReference>
</ItemDefinitionGroup>

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" Condition=" '$(MicrosoftCommonPropsHasBeenImported)' != 'true' "/>

<Import Project="$(CustomAfterNoTargetsProps)" Condition=" '$(CustomAfterNoTargetsProps)' != '' And Exists('$(CustomAfterNoTargetsProps)') " />
Expand Down
2 changes: 1 addition & 1 deletion src/NoTargets/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"inherit": true,
"version": "1.0"
"version": "2.0"
}

0 comments on commit 93ca4c3

Please sign in to comment.