Skip to content

Commit cfe8e01

Browse files
authored
Updates MSBuild references (Buildalyzer#282)
1 parent 752dba3 commit cfe8e01

File tree

7 files changed

+140
-7
lines changed

7 files changed

+140
-7
lines changed

src/Buildalyzer.Workspaces/Buildalyzer.Workspaces.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ ToBeReleased
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
23-
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.4.0" />
22+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" />
23+
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.10.0" />
2424
</ItemGroup>
2525

2626
<ItemGroup>

src/Buildalyzer/Buildalyzer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.Build" Version="17.0.1" />
16-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.0.1" />
15+
<PackageReference Include="Microsoft.Build" Version="17.10.4" />
16+
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.10.4" />
1717
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="[4,)" />
1818
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="[4,)" />
1919
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />

tests/Buildalyzer.Tests/Integration/SimpleProjectsFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class SimpleProjectsFixture
3939
@"SdkNet6SelfContained\SdkNet6SelfContained.csproj",
4040
@"SdkNet6ImplicitUsings\SdkNet6ImplicitUsings.csproj",
4141
@"SdkNet7Project\SdkNet7Project.csproj",
42+
@"SdkNet8CS12FeaturesProject\SdkNet8CS12FeaturesProject.csproj",
4243
@"SdkNetCore2ProjectImport\SdkNetCore2ProjectImport.csproj",
4344
@"SdkNetCore2ProjectWithReference\SdkNetCore2ProjectWithReference.csproj",
4445
@"SdkNetCore2ProjectWithImportedProps\SdkNetCore2ProjectWithImportedProps.csproj",

tests/Buildalyzer.Workspaces.Tests/ProjectAnalyzerExtensionsFixture.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,24 @@ public async Task SupportsNullabilityEnabled()
183183
diagnostics.ShouldBeEmpty();
184184
}
185185

186+
[Test(Description = "Test C#12 features https://github.com/phmonte/Buildalyzer/issues/281")]
187+
188+
public async Task SupportsLangVersion12Features()
189+
{
190+
// Given
191+
StringWriter log = new StringWriter();
192+
IProjectAnalyzer analyzer = GetProjectAnalyzer(@"projects\SdkNet8CS12FeaturesProject\SdkNet8CS12FeaturesProject.csproj", log);
193+
AdhocWorkspace workspace = analyzer.GetWorkspace();
194+
Project project = workspace.CurrentSolution.Projects.Single();
195+
196+
// When
197+
Compilation compilation = await project.GetCompilationAsync();
198+
199+
Diagnostic[] diagnostics = compilation.GetDiagnostics().Where(d => d.Severity == DiagnosticSeverity.Error).ToArray();
200+
201+
diagnostics.ShouldBeEmpty();
202+
}
203+
186204
#if Is_Windows
187205
[Test]
188206
public void HandlesWpfCustomControlLibrary()
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
namespace SdkNet8CS12FeaturesProject
2+
{
3+
// LangVersion12 Features https://github.com/phmonte/Buildalyzer/issues/281
4+
public class Class1
5+
{
6+
// https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12#collection-expressions
7+
public void CollectionExpression()
8+
{
9+
// Create an array:
10+
int[] a = [1, 2, 3, 4, 5, 6, 7, 8];
11+
12+
// Create a list:
13+
List<string> b = ["one", "two", "three"];
14+
15+
// Create a span
16+
Span<char> c = ['a', 'b', 'c', 'd', 'e', 'f', 'h', 'i'];
17+
18+
// Create a jagged 2D array:
19+
int[][] twoD = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
20+
21+
// Create a jagged 2D array from variables:
22+
int[] row0 = [1, 2, 3];
23+
int[] row1 = [4, 5, 6];
24+
int[] row2 = [7, 8, 9];
25+
int[][] twoDFromVariables = [row0, row1, row2];
26+
27+
int[] single = [.. row0, .. row1, .. row2];
28+
foreach (var element in single)
29+
{
30+
Console.Write($"{element}, ");
31+
}
32+
}
33+
34+
public readonly struct Distance(double dx, double dy)
35+
{
36+
public readonly double Magnitude { get; } = Math.Sqrt(dx * dx + dy * dy);
37+
public readonly double Direction { get; } = Math.Atan2(dy, dx);
38+
}
39+
40+
public struct Distance2(double dx, double dy)
41+
{
42+
public readonly double Magnitude => Math.Sqrt(dx * dx + dy * dy);
43+
public readonly double Direction => Math.Atan2(dy, dx);
44+
45+
public void Translate(double deltaX, double deltaY)
46+
{
47+
dx += deltaX;
48+
dy += deltaY;
49+
}
50+
51+
public Distance2() : this(0, 0) { }
52+
}
53+
54+
public class BankAccount(string accountID, string owner)
55+
{
56+
public string AccountID { get; } = ValidAccountNumber(accountID)
57+
? accountID
58+
: throw new ArgumentException("Invalid account number", nameof(accountID));
59+
60+
public string Owner { get; } = string.IsNullOrWhiteSpace(owner)
61+
? throw new ArgumentException("Owner name cannot be empty", nameof(owner))
62+
: owner;
63+
64+
public override string ToString() => $"Account ID: {AccountID}, Owner: {Owner}";
65+
66+
public static bool ValidAccountNumber(string accountID) =>
67+
accountID?.Length == 10 && accountID.All(c => char.IsDigit(c));
68+
}
69+
70+
public class CheckingAccount(string accountID, string owner, decimal overdraftLimit = 0) : BankAccount(accountID, owner)
71+
{
72+
public decimal CurrentBalance { get; private set; } = 0;
73+
74+
public void Deposit(decimal amount)
75+
{
76+
if (amount < 0)
77+
{
78+
throw new ArgumentOutOfRangeException(nameof(amount), "Deposit amount must be positive");
79+
}
80+
CurrentBalance += amount;
81+
}
82+
83+
public void Withdrawal(decimal amount)
84+
{
85+
if (amount < 0)
86+
{
87+
throw new ArgumentOutOfRangeException(nameof(amount), "Withdrawal amount must be positive");
88+
}
89+
if (CurrentBalance - amount < -overdraftLimit)
90+
{
91+
throw new InvalidOperationException("Insufficient funds for withdrawal");
92+
}
93+
CurrentBalance -= amount;
94+
}
95+
96+
public override string ToString() => $"Account ID: {AccountID}, Owner: {Owner}, Balance: {CurrentBalance}";
97+
}
98+
}
99+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

tests/projects/TestProjects.sln

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SdkNet6SelfContained", "Sdk
5252
EndProject
5353
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "VisualBasicNetConsoleApp", "VisualBasicProject\VisualBasicNetConsoleApp.vbproj", "{592A499F-F101-4ED6-82BE-052A5256B1A2}"
5454
EndProject
55-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RazorClassLibraryTest", "RazorClassLibraryTest\RazorClassLibraryTest.csproj", "{96E0901D-99F0-4D28-973E-98F288DF69B7}"
55+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorClassLibraryTest", "RazorClassLibraryTest\RazorClassLibraryTest.csproj", "{96E0901D-99F0-4D28-973E-98F288DF69B7}"
5656
EndProject
57-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResponseFile", "ResponseFile\ResponseFile.csproj", "{B18DD8E6-9D47-4FDD-90EA-8F9C6789BE3A}"
57+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ResponseFile", "ResponseFile\ResponseFile.csproj", "{B18DD8E6-9D47-4FDD-90EA-8F9C6789BE3A}"
5858
EndProject
59-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SdkNet7Project", "SdkNet7Project\SdkNet7Project.csproj", "{8862BA17-36B7-470E-B293-D02E18FD5E4D}"
59+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SdkNet7Project", "SdkNet7Project\SdkNet7Project.csproj", "{8862BA17-36B7-470E-B293-D02E18FD5E4D}"
60+
EndProject
61+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SdkNet8CS12FeaturesProject", "SdkNet8CS12FeaturesProject\SdkNet8CS12FeaturesProject.csproj", "{6DDD74AB-8821-4267-8DC2-8864A3BB5871}"
6062
EndProject
6163
Global
6264
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -172,6 +174,10 @@ Global
172174
{8862BA17-36B7-470E-B293-D02E18FD5E4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
173175
{8862BA17-36B7-470E-B293-D02E18FD5E4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
174176
{8862BA17-36B7-470E-B293-D02E18FD5E4D}.Release|Any CPU.Build.0 = Release|Any CPU
177+
{6DDD74AB-8821-4267-8DC2-8864A3BB5871}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
178+
{6DDD74AB-8821-4267-8DC2-8864A3BB5871}.Debug|Any CPU.Build.0 = Debug|Any CPU
179+
{6DDD74AB-8821-4267-8DC2-8864A3BB5871}.Release|Any CPU.ActiveCfg = Release|Any CPU
180+
{6DDD74AB-8821-4267-8DC2-8864A3BB5871}.Release|Any CPU.Build.0 = Release|Any CPU
175181
EndGlobalSection
176182
GlobalSection(SolutionProperties) = preSolution
177183
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)