Skip to content

Commit

Permalink
(chore) Upgrade packages (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfederm authored Oct 1, 2024
1 parent 9b795d8 commit a2a1e3c
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 66 deletions.
8 changes: 7 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project>

<!-- Dogfooding - add the latest ReferenceTrimmer package to this repo's build.
Expand Down Expand Up @@ -30,6 +30,12 @@

<!-- Embed symbols in the assembly for easier debugging -->
<DebugType>embedded</DebugType>

<!--
This all runs in the context of other processes, so we don't have control of the dependencies.
Furthermore, we intentionally target lower versions for best compatibility.
-->
<NuGetAudit>false</NuGetAudit>
</PropertyGroup>

<!-- Packaging -->
Expand Down
1 change: 1 addition & 0 deletions ReferenceTrimmer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
Directory.Build.props = Directory.Build.props
Directory.Build.rsp = Directory.Build.rsp
global.json = global.json
LICENSE = LICENSE
NuGet.Config = NuGet.Config
README.md = README.md
Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"msbuild-sdks": {
"Microsoft.Build.NoTargets": "3.7.56",
"MSTest.Sdk": "3.6.0"
}
}
11 changes: 6 additions & 5 deletions src/Loggers/MSVC/ForwardingLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,14 @@ private static string EscapeJsonChars(string str)

private void OnMessageRaised(object sender, BuildMessageEventArgs e)
{
if (string.IsNullOrEmpty(e.ProjectFile))
string? projectFilePath = e.ProjectFile;
string? message = e.Message;

if (string.IsNullOrEmpty(projectFilePath) || message is null)
{
return;
}

string projectFilePath = e.ProjectFile;

if (!_projects.TryGetValue(projectFilePath, out ProjectStateLibs? projState))
{
return;
Expand All @@ -246,14 +247,14 @@ private void OnMessageRaised(object sender, BuildMessageEventArgs e)
switch (projState.ProjectState)
{
case State.LinkStarted:
if (e.Message.IndexOf("Unused libraries:", StringComparison.OrdinalIgnoreCase) != -1)
if (message!.IndexOf("Unused libraries:", StringComparison.OrdinalIgnoreCase) != -1)
{
projState.ProjectState = State.UnusedLibsStarted;
}
break;

case State.UnusedLibsStarted:
string lib = e.Message.Trim();
string lib = message!.Trim();
if (lib.Length > 0)
{
try
Expand Down
2 changes: 1 addition & 1 deletion src/Loggers/ReferenceTrimmer.Loggers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.3.1" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.6.3" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Package/ReferenceTrimmer.Package.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.Build.NoTargets/3.7.0">
<Project Sdk="Microsoft.Build.NoTargets">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
20 changes: 17 additions & 3 deletions src/Tasks/CollectDeclaredReferencesTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,12 @@ private Dictionary<string, PackageInfo> GetPackageInfos()
var lockFile = LockFileUtilities.GetLockFile(ProjectAssetsFile, NullLogger.Instance);
var packageFolders = lockFile.PackageFolders.Select(item => item.Path).ToList();

var nugetFramework = NuGetFramework.ParseComponents(TargetFrameworkMoniker, TargetPlatformMoniker);
LockFileTarget? nugetTarget = lockFile.GetTarget(nugetFramework, RuntimeIdentifier);
LockFileTarget? nugetTarget = null;
if (!string.IsNullOrEmpty(TargetFrameworkMoniker))
{
var nugetFramework = NuGetFramework.ParseComponents(TargetFrameworkMoniker!, TargetPlatformMoniker);
nugetTarget = lockFile.GetTarget(nugetFramework, RuntimeIdentifier);
}

List<LockFileTargetLibrary> nugetLibraries;
if (nugetTarget?.Libraries is not null)
Expand All @@ -222,7 +226,12 @@ private Dictionary<string, PackageInfo> GetPackageInfos()
var nugetDependents = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
foreach (LockFileTargetLibrary nugetLibrary in nugetLibraries)
{
var packageId = nugetLibrary.Name;
string? packageId = nugetLibrary.Name;
if (packageId is null)
{
continue;
}

foreach (var dependency in nugetLibrary.Dependencies)
{
if (!nugetDependents.TryGetValue(dependency.Id, out var parents))
Expand All @@ -238,6 +247,11 @@ private Dictionary<string, PackageInfo> GetPackageInfos()
// Get the transitive closure of assemblies included by each package
foreach (LockFileTargetLibrary nugetLibrary in nugetLibraries)
{
if (nugetLibrary.Name is null)
{
continue;
}

string nugetLibraryRelativePath = lockFile.GetLibrary(nugetLibrary.Name, nugetLibrary.Version).Path;
string nugetLibraryAbsolutePath = packageFolders
.Select(packageFolder => Path.Combine(packageFolder, nugetLibraryRelativePath))
Expand Down
4 changes: 2 additions & 2 deletions src/Tasks/ReferenceTrimmer.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.3.1" />
<PackageReference Include="NuGet.ProjectModel" Version="6.3.0" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.6.3" />
<PackageReference Include="NuGet.ProjectModel" Version="6.11.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Shared\*.cs" />
Expand Down
Loading

0 comments on commit a2a1e3c

Please sign in to comment.