Skip to content

Commit f8d955d

Browse files
edvilmeMiYanni
andauthored
reference-list: Expand includes (#49168)
Co-authored-by: Michael Yanni <miyanni@microsoft.com>
1 parent 852aab1 commit f8d955d

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

eng/restore-toolset.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function CreateVSShortcut()
105105
$slnPath = Join-Path $RepoRoot 'sdk.slnx'
106106
$commandToLaunch = "& '$scriptPath'; & '$devenvPath' '$slnPath'"
107107
$powershellPath = '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe'
108-
$shortcutPath = Join-Path $ArtifactsDir 'VS with sdk.sln.lnk'
108+
$shortcutPath = Join-Path $ArtifactsDir 'VS with sdk.slnx.lnk'
109109

110110
# https://stackoverflow.com/a/9701907/294804
111111
# https://learn.microsoft.com/en-us/troubleshoot/windows-client/admin-development/create-desktop-shortcut-with-wsh

sdk.slnx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<Project Path="src/Containers/packaging/package.csproj" />
8686
</Folder>
8787
<Folder Name="/src/Layout/">
88+
<Project Path="src/Layout/finalizer/finalizer.csproj" />
8889
<Project Path="src/Layout/pkg/dotnet-sdk.proj" Type="C#" />
8990
<Project Path="src/Layout/redist/redist.csproj" />
9091
<Project Path="src/Layout/redist/tools/tool_fsc.csproj" />
@@ -96,7 +97,6 @@
9697
<Project Path="src/Layout/VS.Redist.Common.NetCore.SdkPlaceholder/VS.Redist.Common.NetCore.SdkPlaceholder.proj" Type="C#" />
9798
<Project Path="src/Layout/VS.Redist.Common.NetCore.Templates/VS.Redist.Common.NetCore.Templates.proj" Type="C#" />
9899
<Project Path="src/Layout/VS.Redist.Common.NetCore.Toolset/VS.Redist.Common.NetCore.Toolset.proj" Type="C#" />
99-
<Project Path="src/Tasks/sdk-tasks/sdk-tasks.csproj" />
100100
</Folder>
101101
<Folder Name="/src/RazorSdk/" />
102102
<Folder Name="/src/RazorSdk/Sdk/">
@@ -168,6 +168,7 @@
168168
<Project Path="src/Tasks/Microsoft.NET.Build.Extensions.Tasks/Microsoft.NET.Build.Extensions.Tasks.csproj" />
169169
<Project Path="src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Microsoft.NET.Build.Tasks.UnitTests.csproj" />
170170
<Project Path="src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj" />
171+
<Project Path="src/Tasks/sdk-tasks/sdk-tasks.csproj" />
171172
</Folder>
172173
<Folder Name="/src/WasmSdk/" />
173174
<Folder Name="/src/WasmSdk/Targets/">
@@ -352,5 +353,4 @@
352353
<Folder Name="/test/Compatibility/GenAPI/">
353354
<Project Path="test/Microsoft.DotNet.GenAPI.Tests/Microsoft.DotNet.GenAPI.Tests.csproj" />
354355
</Folder>
355-
<Project Path="src/Layout/finalizer/finalizer.csproj" />
356356
</Solution>

src/Cli/dotnet/Commands/Reference/List/ReferenceListCommand.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
#nullable disable
55

66
using System.CommandLine;
7+
using Microsoft.Build.Construction;
78
using Microsoft.Build.Evaluation;
9+
using Microsoft.Build.Exceptions;
10+
using Microsoft.Build.Execution;
811
using Microsoft.DotNet.Cli.Commands.Hidden.List;
912
using Microsoft.DotNet.Cli.Extensions;
1013
using Microsoft.DotNet.Cli.Utils;
@@ -15,8 +18,7 @@ internal class ReferenceListCommand : CommandBase
1518
{
1619
private readonly string _fileOrDirectory;
1720

18-
public ReferenceListCommand(
19-
ParseResult parseResult) : base(parseResult)
21+
public ReferenceListCommand(ParseResult parseResult) : base(parseResult)
2022
{
2123
ShowHelpOrErrorIfAppropriate(parseResult);
2224

@@ -29,22 +31,30 @@ public ReferenceListCommand(
2931
public override int Execute()
3032
{
3133
var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), _fileOrDirectory, false);
32-
3334
var p2ps = msbuildProj.GetProjectToProjectReferences();
3435
if (!p2ps.Any())
3536
{
36-
Reporter.Output.WriteLine(string.Format(
37-
CliStrings.NoReferencesFound,
38-
CliStrings.P2P,
39-
_fileOrDirectory));
37+
Reporter.Output.WriteLine(string.Format(CliStrings.NoReferencesFound, CliStrings.P2P, _fileOrDirectory));
38+
return 0;
39+
}
40+
41+
ProjectRootElement projectRootElement;
42+
try
43+
{
44+
projectRootElement = ProjectRootElement.Open(_fileOrDirectory);
45+
}
46+
catch (InvalidProjectFileException ex)
47+
{
48+
Reporter.Error.WriteLine(string.Format(CliStrings.InvalidProjectWithExceptionMessage, _fileOrDirectory, ex.Message));
4049
return 0;
4150
}
4251

52+
ProjectInstance projectInstance = new(projectRootElement);
4353
Reporter.Output.WriteLine($"{CliStrings.ProjectReferenceOneOrMore}");
4454
Reporter.Output.WriteLine(new string('-', CliStrings.ProjectReferenceOneOrMore.Length));
45-
foreach (var p2p in p2ps)
55+
foreach (var item in projectInstance.GetItems("ProjectReference"))
4656
{
47-
Reporter.Output.WriteLine(p2p.Include);
57+
Reporter.Output.WriteLine(item.EvaluatedInclude);
4858
}
4959

5060
return 0;

test/dotnet.Tests/CommandTests/Reference/List/GivenDotnetListReference.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Xml;
45
using Microsoft.DotNet.Cli.Utils;
56
using Msbuild.Tests.Utilities;
67

@@ -207,6 +208,26 @@ public void ItPrintsMultipleReferences()
207208
cmd.StdOut.Should().BeVisuallyEquivalentTo(OutputText);
208209
}
209210

211+
[Fact]
212+
public void ItPrintsReferenceWithMSBuildPropertyInPath()
213+
{
214+
var testDir = _testAssetsManager.CreateTestDirectory().Path;
215+
var lib = NewLib(testDir, "lib");
216+
string OutputText = CliStrings.ProjectReferenceOneOrMore;
217+
OutputText += $@"
218+
{new string('-', OutputText.Length)}
219+
{lib.Path}..\ref1\ref1.csproj";
220+
221+
string ref1Name = NewLib(testDir, "ref1").CsProjName;
222+
AddInvalidRef($"$(MSBuildThisFileDirectory)..\\ref1\\{ref1Name}", lib);
223+
224+
var cmd = new ListReferenceCommand(Log)
225+
.WithProject(lib.CsProjPath)
226+
.Execute();
227+
cmd.Should().Pass();
228+
cmd.StdOut.Should().BeVisuallyEquivalentTo(OutputText);
229+
}
230+
210231
private TestSetup Setup([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(Setup), string identifier = "")
211232
{
212233
return new TestSetup(
@@ -243,5 +264,19 @@ private void AddValidRef(string path, ProjDir proj)
243264
.Execute(path)
244265
.Should().Pass();
245266
}
267+
268+
private static void AddInvalidRef(string referenceValue, ProjDir proj)
269+
{
270+
var csprojXml = new XmlDocument();
271+
csprojXml.Load(proj.CsProjPath);
272+
273+
var projectReference = csprojXml.CreateElement("ProjectReference");
274+
projectReference.SetAttribute("Include", referenceValue);
275+
csprojXml.DocumentElement
276+
?.AppendChild(csprojXml.CreateElement("ItemGroup"))
277+
?.AppendChild(projectReference);
278+
279+
csprojXml.Save(proj.CsProjPath);
280+
}
246281
}
247282
}

0 commit comments

Comments
 (0)