Skip to content

Commit 4838941

Browse files
authored
Implenets cleaner .NET SDK version light up (#341)
* Roslyn compiler versions and .NET SDK are intimately tied so detecting the SDK is a means to detect if certain compiler versions are used. - Specifically the analyzers and tests can only use/test support that is IN the version of compiler used for the projects the analyzer is analyzing. That is, the analyzer cannot be configured for a later version. This makes pre-release analyzer features and testing VERY difficult. - A Prerelease SDK must be used for everything to work. * Minor doc updates
1 parent 7d37b97 commit 4838941

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

Directory.Build.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
<ImplicitUsings>disable</ImplicitUsings>
8484
<!-- NOTE: Top-Level statements blocked as an error in .editorconfig and ImplicitUsings 'feature' VERIFIED in the targets file -->
8585
</PropertyGroup>
86+
87+
<!--
88+
Apply SyleCop settings to all projects; It is at least plausible to do this in a .editorconfig but there's no docs on
89+
how. Only a PR and multiple bugs/discussions pointing to it. It's too big to decipher to make it worth using. Docs please.
90+
-->
8691
<ItemGroup Condition="'$(NoCommonAnalyzers)'!='true'">
8792
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
8893
</ItemGroup>

Directory.Build.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<Project InitialTargets="VerifyProjectSettings;ShowBuildParameters;EnsureBuildOutputPaths">
2+
3+
<!--This must go in the targets as the directory imports occur BEFORE $(NETCoreSdkVersion) is set and would end up blank -->
4+
<PropertyGroup Condition="'$(NETCoreSdkVersion)'!='' AND $([MSBuild]::VersionGreaterThanOrEquals('$(NETCoreSdkVersion)', '10.0.0'))">
5+
<DefineConstants>$(DefineConstants);NET_SDK_10_OR_GREATER</DefineConstants>
6+
</PropertyGroup>
7+
28
<!--
39
Since Nuget.config is configured to include the build output location this
410
will ensure the folder exists during restore so that it won't fail.
@@ -19,6 +25,7 @@
1925
<Message Importance="normal" Text=" FileVersion: $(FileVersion)"/>
2026
<Message Importance="normal" Text=" Platform: $(Platform)"/>
2127
<Message Importance="normal" Text=" Configuration: $(Configuration)"/>
28+
<Message Importance="normal" Text=" NETCoreSdkVersion: $(NETCoreSdkVersion)"/>
2229
</Target>
2330

2431
<Target Name="VerifyProjectSettings" Condition="'$(MSBuildProjectExtension)'=='.csproj'">

src/Analyzers/RepositoryVerifier.UT/ExtensionsKeywordAnalyzerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
// This isn't a normal built-in define; but follows the pattern for built-in defines and expresses the intent.
55
// There is no Known way to "light up" at runtime for functionality available in newer versions
6-
#if COMPILER_5_OR_GREATER
6+
// See: Directory.Build.targets for how this is set. (Roslyn compiler v5.x is included in .NET 10)
7+
#if NET_SDK_10_OR_GREATER
78
using System.Threading.Tasks;
89

910
using Microsoft.CodeAnalysis;

src/Analyzers/RepositoryVerifier/ExtensionKeywordAnalyzer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
// This isn't a normal built-in define; but follows the pattern for built-in defines and expresses the intent.
55
// There is no Known way to "light up" at runtime for functionality available in newer versions
6-
#if COMPILER_5_OR_GREATER
6+
// See: Directory.Build.targets for how this is set. (Roslyn compiler v5.x is included in .NET 10)
7+
#if NET_SDK_10_OR_GREATER
78
using System.Collections.Immutable;
89

910
using Microsoft.CodeAnalysis;

src/Interop/Ubiquity.NET.Llvm.Interop/ReadMe.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ This library contains the low level interop between managed code and the native
1515
for more info]
1616

1717
Firstly it's young, poorly understood, barely even documented and not what is considered
18-
by many as stable/mature yet. But, mostly because it requires everything to compile AOT to work. That
19-
is, it's all or nothing and doesn't support use in an either or model (traditional JIT runtime,
20-
or AOT). Somethings are not yet supporting AOT/Trimming scenarios. (In the case of the samples
21-
in this repo the DGML graph builder used employs XML serialization, which in turn requires
22-
dynamic reflection to work. This required a custom solution to resolve. So, as great a feature
23-
AOT is it is not without issues at present. Perhaps over time it will become the normal state
24-
and more libraries will build in a way as to support it. (This library has a motivation to go
25-
there in that it's broader use is specifically for AOT code generation! Thus it's a bit on the
26-
"bleeding edge" of things.)
18+
by many as stable/mature yet. But, mostly because it requires everything to compile AOT to
19+
work. That is, it's all or nothing and doesn't support use in an either or model
20+
(traditional JIT runtime, or AOT). Somethings are not yet supporting AOT/Trimming scenarios.
21+
22+
In the case of the samples in this repo the DGML graph builder used employs XML
23+
serialization, which in turn requires dynamic reflection to work. This required a custom
24+
solution to resolve. So, as great a feature AOT is it is not without issues at present.
25+
Perhaps over time it will become the normal state and more libraries will build in a way as
26+
to support it. (This library has a motivation to go there in that it's broader use is
27+
specifically for AOT code generation! Thus it's a bit on the "bleeding edge" of things.)

0 commit comments

Comments
 (0)