Skip to content
Draft
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 @@ -219,9 +219,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<TrimmerSingleWarn Condition=" '$(TrimmerSingleWarn)' == '' ">true</TrimmerSingleWarn>
</PropertyGroup>

<!-- Root the main assembly entry point. -->
<!-- Root the main assembly entry point for non-library projects. -->
<ItemGroup>
<TrimmerRootAssembly Include="@(IntermediateAssembly->'%(Filename)')" RootMode="EntryPoint" />
<TrimmerRootAssembly Include="@(IntermediateAssembly->'%(Filename)')" RootMode="EntryPoint" Condition="'$(OutputType)' != 'Library'" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Xunit;

#nullable enable

namespace ILLink.Tasks.Tests
{
public class MicrosoftNETILLinkTargetsTests
{
[Fact]
public void EntryPointRootIsNotAddedForLibraryProjects()
{
XDocument targets = XDocument.Load(GetTargetsFilePath());

XElement entryPointRoot = targets.Descendants()
.Where(element => element.Name.LocalName == "TrimmerRootAssembly")
.Single(element =>
GetAttributeValue(element, "Include") == "@(IntermediateAssembly->'%(Filename)')" &&
GetAttributeValue(element, "RootMode") == "EntryPoint");

Assert.Equal("'$(OutputType)' != 'Library'", GetAttributeValue(entryPointRoot, "Condition"));
}

private static string GetTargetsFilePath()
{
DirectoryInfo? directory = new DirectoryInfo(AppContext.BaseDirectory);

while (directory is not null)
{
string targetsFilePath = Path.Combine(directory.FullName, "src", "tools", "illink", "src", "ILLink.Tasks", "build", "Microsoft.NET.ILLink.targets");
if (File.Exists(targetsFilePath))
return targetsFilePath;

directory = directory.Parent;
}

throw new FileNotFoundException("Could not locate Microsoft.NET.ILLink.targets.");
}

private static string GetAttributeValue(XElement element, string attributeName)
=> element.Attribute(attributeName)?.Value ?? throw new InvalidDataException($"Missing '{attributeName}' attribute.");
}
}
Loading