Coder Social home page Coder Social logo

referenceassemblyannotator's Introduction

Reference Assembly Annotator

IL weaver for adding nullability annotations to .NET Framework, .NET Standard, and .NET Core reference assemblies.

Build status

codecov

Join the chat at https://gitter.im/tunnelvisionlabs/ReferenceAssemblyAnnotator

Requirements

  • Build: C# compiler version 3.2 Beta 2 or newer (ships with Visual Studio 2019 version 16.3 Preview 2 and newer). Older versions of the compiler interpret nullable metadata differently, which can lead to incorrect build warnings.
  • Editing experience: Visual Studio 2019 version 16.3 Preview 2 or newer.

Usage

Assemblies included by default

  • .NET Framework targets
    • mscorlib
    • System
    • System.Core
    • System.Data
    • System.Drawing
    • System.IO.Compression.FileSystem
    • System.Numerics
    • System.Runtime.Serialization
    • System.Xml
    • System.Xml.Linq
  • .NET Standard targets
    • All assemblies which are defined by the .NET Standard
  • .NET Core targets
    • All reference assemblies defined by .NET Core

Example configuration

<PropertyGroup>
  <!-- By default, the nullable attributes from dotnet/coreclr are included as source code with 'internal'
       accessibility. Uncomment to suppress this if the attributes are included from another source and/or
       are not needed. -->
  
  <!-- <GenerateNullableAttributes>false</GenerateNullableAttributes> -->
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />

  <!-- Specifies the version of Microsoft.NETCore.App.Ref to obtain nullability information from. -->
  <PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[5.0.0]" />
</ItemGroup>

Minimal:

<ItemGroup>
  <PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />
  <PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[5.0.0]" />
</ItemGroup>

Configuration reference

  • MSBuild properties
    • <AnnotatedReferenceAssemblyVersion>: Specifies the version of Microsoft.NETCore.App.Ref to obtain nullability information from. This is required if there are multiple PackageDownload versions of Microsoft.NETCore.App.Ref.
    • <GenerateNullableAttributes>: Set to True to include definitions of nullability attributes in the build; otherwise, False to exclude the definitions. The default value is True.
  • MSBuild items
    • <UnannotatedReferenceAssembly>: Specifies reference assemblies to annotate. This is only required for assemblies that are not automatically annotated by this package.

Releases

NuGet NuGet Beta

referenceassemblyannotator's People

Contributors

jnm2 avatar sharwell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

referenceassemblyannotator's Issues

Regenerate annotated assemblies when annotator version changes without needing rebuild or clean

Having to rebuild or clean after updating to a new package version would require me to think about implementation details that I will never remember and that I'd prefer not to care about when I use this.

Would you want to add a annotator-version or similar file in the folder with the annotated assemblies containing the package version of TunnelVisionLabs.ReferenceAssemblyAnnotator and the AnnotatedReferenceAssemblyVersion value? That could be checked during normal build to see whether the assemblies need to be regenerated.

[Bug]: Breaks with multiple framework targets

On a brand new project with this csproj file, everything compiles fine:

<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
		<TargetFramework>netstandard2.0</TargetFramework>
	</PropertyGroup>

	<ItemGroup>
		<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />

		<!-- Specifies the version of Microsoft.NETCore.App.Ref to obtain nullability information from. -->
		<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[6.0.0]" />
	</ItemGroup>

</Project>

However, if the csproj file is changed slightly, it no longer does:

<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
		<TargetFrameworks>netstandard2.0</TargetFrameworks>
	</PropertyGroup>

	<ItemGroup>
		<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />

		<!-- Specifies the version of Microsoft.NETCore.App.Ref to obtain nullability information from. -->
		<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[6.0.0]" />
	</ItemGroup>

</Project>

In Visual Studio 2022, I get this error:

MSB4184	The expression """.Substring(1)" cannot be evaluated. startIndex cannot be larger than length of string. Parameter name: startIndex

This points to a line in TunnelVisionLabs.ReferenceAssemblyAnnotator.targets:

<PropertyGroup Condition="'$(TargetFrameworkVersion.Substring(1))' &gt;= '2.0'">

netcoreapp2.1 is not annotated

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netcoreapp2.1</TargetFrameworks>
    <LangVersion>8</LangVersion>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <PropertyGroup>
    <AnnotatedReferenceAssemblyVersion>3.0.0</AnnotatedReferenceAssemblyVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.90" PrivateAssets="all" />
    <PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[$(AnnotatedReferenceAssemblyVersion)]" />
  </ItemGroup>

</Project>
using System.Diagnostics;

public static class C
{
    public static void M(string? x)
    {
        Debug.Assert(x is object);

        // CS8602 Dereference of a possibly null reference
        x.ToString();
    }
}

NRE in SuppressibleLoggingHelper constructor

Looks like disabledWarnings must be null:

public SuppressibleLoggingHelper(TaskLoggingHelper helper, string requiredPrefix, string disabledWarnings)
{
_helper = helper;
if (string.IsNullOrWhiteSpace(requiredPrefix))
throw new ArgumentException("A required warning prefix must be supplied.", nameof(requiredPrefix));
_requiredPrefix = requiredPrefix;
_disabledWarnings = disabledWarnings
.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)
.Select(item => item.Trim())
.Where(item => item.StartsWith(requiredPrefix, StringComparison.Ordinal))
.ToImmutableHashSet(StringComparer.Ordinal);
}

'AllowNullAttribute::.ctor()' is declared in another module and needs to be imported

@sharwell We missed something in #43.

The "AnnotatorBuildTask" task failed unexpectedly.
System.ArgumentException: Member 'System.Void System.Diagnostics.CodeAnalysis.AllowNullAttribute::.ctor()' is declared in another module and needs to be imported
   at Mono.Cecil.MetadataBuilder.LookupToken(IMetadataTokenProvider provider)
   at Mono.Cecil.MetadataBuilder.AddCustomAttributes(ICustomAttributeProvider owner)
   at Mono.Cecil.MetadataBuilder.AddParameter(UInt16 sequence, ParameterDefinition parameter, ParamTable table)
   at Mono.Cecil.MetadataBuilder.AddParameters(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddTypes()
   at Mono.Cecil.MetadataBuilder.BuildTypes()
   at Mono.Cecil.MetadataBuilder.BuildModule()
   at Mono.Cecil.MetadataBuilder.BuildMetadata()
   at Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_0(MetadataBuilder builder, MetadataReader _)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
   at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
   at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
   at TunnelVisionLabs.ReferenceAssemblyAnnotator.Program.Main(Nullable`1 log, String referenceAssembly, String annotatedReferenceAssembly, String outputAssembly)
   at TunnelVisionLabs.ReferenceAssemblyAnnotator.AnnotatorBuildTask.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

https://dev.azure.com/guorg/Gu.Roslyn.Extensions/_build/results?buildId=332&view=logs&jobId=12f1170f-54f2-53f3-20dd-22fc7dff55f9&taskId=006e6f7c-8314-5e02-a3df-483f3a1f4cfa&lineStart=15&lineEnd=37&colStart=1&colEnd=474

"AnnotatorBuildTask" task failed unexpectedly with Mono.Cecil.AssemblyResolutionException

This is alpha 77 on Shouldly's Ubuntu build:

Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]

I'm not sure whether this is recoverable or whether it should just be turned into a nicer error.

Stack trace:

at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.TypeReference.Resolve() [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.Mixin.CheckedResolve(TypeReference self) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeEnum(TypeReference enum_type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeElementValue(TypeReference type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArgument(TypeReference type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeNamedArgument(Collection`1& fields, Collection`1& properties) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeNamedArguments(UInt16 count, Collection`1& fields, Collection`1& properties) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.CustomAttribute.<Resolve>b__35_0(CustomAttribute attribute, MetadataReader reader) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleDefinition.Read[TItem](TItem item, Action`2 read) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.CustomAttribute.get_ConstructorArguments() [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.ReadCustomAttributes(ICustomAttributeProvider provider) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.ReadType(TypeDefinition type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.ReadTypes(Collection`1 types) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.ReadModule(ModuleDefinition module, Boolean resolve_attributes) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.<ReadModule>b__2_0(ModuleDefinition module, MetadataReader reader) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleDefinition.Read[TItem](TItem item, Action`2 read) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.ReadModule() [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleReader.CreateModule(Image image, ReaderParameters parameters) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleDefinition.ReadModule(Disposable`1 stream, String fileName, ReaderParameters parameters) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at TunnelVisionLabs.ReferenceAssemblyAnnotator.Program.Main(Nullable`1 log, String referenceAssembly, String annotatedReferenceAssembly, String outputAssembly) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at TunnelVisionLabs.ReferenceAssemblyAnnotator.AnnotatorBuildTask.Execute() [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]

Incorrect warning about StringComparer differing in nullability from IEqualityComparer<string?>

I'm not sure of the cause, but I'm seeing this on net472 using alpha 53 and Microsoft.NETCore.App.Ref 3.0.0:

void M(IEnumerable<string?> values)
{
    // CS8620 Argument of type 'StringComparer' cannot be used for parameter 'comparer' of type
    // 'IEqualityComparer<string?>' in 'IEnumerable<string?> Enumerable.Distinct<string?>(
    // IEnumerable<string?> source, IEqualityComparer<string?> comparer)' due to differences in
    // the nullability of reference types.
    //              ↓
    values.Distinct(StringComparer.CurrentCultureIgnoreCase);
}

StringComparer does in fact implement IEqualityComparer<string?>, not IEqualityComparer<string>. If I target netcoreapp3.0, the warning goes away.

Annotate NuGet packages

Currently only reference assemblies for the target framework are supported. It would be nice to support additional libraries as well. For example, users referencing Microsoft.CodeAnalysis.Workspaces could build against the 1.2.1 packages, and annotate them with nullability information being added to the 3.3.0 release.

Support older versions of .NET Framework

My company has some projects that extend third-party .NET Framework 3.5 software. We don't have control over the entry point, so these projects are largely stuck with the world as it was eleven years ago.

There doesn't seem to be any reason not to allow this package to annotate as far back as net35, does there? From the perspective of what I understand this package to do, net35 is net472, only with fewer APIs.

I extracted https://globalcdn.nuget.org/packages/tunnelvisionlabs.referenceassemblyannotator.1.0.0-alpha.53.nupkg to %userprofile%/.nuget/packages/tunnelvisionlabs.referenceassemblyannotator.1.0.0/alpha.53, deleted the signature, and changed the nuspec dependency to .NETFramework,3.5. The package then installs successfully.

Would you accept a PR to permit this scenario?

NETSDK1022 error for default compile items when using WPF with .NET 6 SDK caused by our workaround for earlier SDKs

I'm reproing:

Error NETSDK1022: Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'C:\Users\Joseph.nuget\packages\tunnelvisionlabs.referenceassemblyannotator\1.0.0-alpha.160\build\NullableAttributes.cs'

And I think this could be #82 causing problems now that the .NET 6 SDK fixed the problem we were working around. <IncludePackageReferencesDuringMarkupCompilation> is on by default starting with SDK 6, and we should have a CI test with and also without.

Net35 projects lose reference to System.Data when referencing ReferenceAssemblyAnnotator

@sharwell You had mentioned that the net35 reference assemblies include one mixed-mode implementation assembly, System.Data, and that Mono.Cecil fails to rewrite mixed-mode assemblies. I'm seeing this in a net35 project with an explicit (necessary) reference to System.Data:

MSB3267 The primary reference "System.Data", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v3.5". To resolve this problem, either remove the reference "System.Data" or retarget your application to a framework version which contains "System.Data".

Along with compiler errors due to missing types from that assembly.

I wonder if https://github.com/0xd4d/dnlib can write mixed-mode assemblies. If not, I wonder if either Cecil or dnlib can strip out the mixed-mode stuff since this assembly is only being used as a ref assembly. If not, the original non-rewritten System.Data "reference" assembly should stay referenced so that the project can compile.

Nullability attributes are not included in WPF temp projects which are part of the WPF build process

Usage of any nullability attributes in a WPF project result in this:

CS0122 'NotNullWhenAttribute' is inaccessible due to its protection level

The error is reported as coming from a project named YourProjectName_*_wpftmp.csproj.

The reason is that the NullableAttributes.cs file is not included in such a way that this WPF build task can see it:

https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft.WinFx.targets#L401
https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs#L90

Repro:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[3.1.0]" />
    <PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.154" PrivateAssets="all" />
  </ItemGroup>
</Project>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        _ = typeof(NotNullWhenAttribute);
        this.InitializeComponent();
    }
}

Look for performance opportunities

AnnotatorBuildTask is taking 24.6 seconds for rebuilds out of 48.3 seconds total, more than doubling the build time. I guess the first step would be to profile?

image

Duplicate definition warnings for nullability attributes

The error list has one warning per usage of one of the nullability attributes in my own code:

CS0436 The type 'AllowNullAttribute' in '.nuget\packages\tunnelvisionlabs.referenceassemblyannotator\1.0.0-alpha.69\build\NullableAttributes.cs' conflicts with the imported type 'AllowNullAttribute' in <project name>. Using the type defined in '.nuget\packages\tunnelvisionlabs.referenceassemblyannotator\1.0.0-alpha.69\build\NullableAttributes.cs'.

This is after git clean -fxd with VS closed and then building the solution once or a few times.

This is an SDK-style project that does not define any attributes except by referencing this package.

Automatically annotate .NET Framework assemblies

Currently references to .NET Standard 1.x and .NET Standard 2.0 assemblies are automatically rewritten during the build. However, in .NET Framework builds only mscorlib is automatically rewritten. It would be nice to automatically include other .NET Framework assemblies automatically.

Include PackageDownload in targets

I don't like adding the boilerplate PackageDownload line to every csproj. It would be nice to have this in the targets:

  <ItemGroup Condition="'$(AnnotatedReferenceAssemblyVersion)' != ''">
    <PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[$(AnnotatedReferenceAssemblyVersion)]" />
  </ItemGroup>

If control of the package name is desired, we could do this:

  <PropertyGroup Condition="'$(AnnotatedReferenceAssemblyPackageName)' != ''">
    <AnnotatedReferenceAssemblyPackageName>Microsoft.NETCore.App.Ref</AnnotatedReferenceAssemblyPackageName>
  </PropertyGroup>

  <ItemGroup Condition="'$(AnnotatedReferenceAssemblyVersion)' != ''">
    <PackageDownload Include="$(AnnotatedReferenceAssemblyPackageName)" Version="[$(AnnotatedReferenceAssemblyVersion)]" />
  </ItemGroup>

Create annotated reference assemblies nuget packages

I noticed that on large solutions, with 100s of project, that the annotator creates reference packages in every project taking up considerable amount of diskspace.

So I created a tiny project, target every framework and run it once. Then I packed the resulting sets of annotated dlls into a nuget package per framework. Now we reference these and save on diskspace. Currently published to our corporate nuget server.

I had expected to safe on time as well, but your tool is efficient that on a fast SSD it doesn't seem to make much difference.

If you think this could be a solution for your caching problem, I can create a PR here.

I don't know if we are allowed by MS to publish these annotated packages on NuGet or why MS hasn't created annotated reference packages themselves to aid in take up of nullable reference types.

IOException: The file 'obj\Debug\net35\annotated\System.Core.xml' already exists.

error MSB4018: The "AnnotatorBuildTask" task failed unexpectedly.
System.IO.IOException: The file 'obj\Debug\net35\annotated\System.Core.xml' already exists.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at System.IO.File.Copy(String sourceFileName, String destFileName)
at TunnelVisionLabs.ReferenceAssemblyAnnotator.AnnotatorBuildTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

@sharwell If the file exists, would there ever be a reason that it would need to be updated? Rather than passing overwrite: true, maybe the IOException could be swallowed based on the error code (probably ERROR_FILE_EXISTS).

annotator is broken when microsoft.netcore.app.ref isn't in NuGetPackageRoot

The use of $(NuGetPackageRoot) here:

<_AnnotatedReferenceAssemblyDirectoryContents Include="$(NuGetPackageRoot)\microsoft.netcore.app.ref\$(AnnotatedReferenceAssemblyVersion)\ref\*\*.dll" />

obviously doesn't work if microsoft.netcore.app.ref isn't in the package root, but this is possible when using fallback package paths.

I think ideally this should be getting the path as resolved by nuget, but I'm not quite sure how to go about doing that.

Targets try to evaluate GetDirectoryName('') and cause "path is not of a legal form" error (support netcoreapp3.0 and netstandard2.1)

C:\Users\appveyor.nuget\packages\tunnelvisionlabs.referenceassemblyannotator\1.0.0-alpha.77\build\TunnelVisionLabs.ReferenceAssemblyAnnotator.targets(129,47): error MSB4184: The expression "[System.IO.Path]::GetDirectoryName('')" cannot be evaluated. The path is not of a legal form.

Project: https://github.com/GuOrg/Gu.Wpf.DataGrid2D/blob/6797e4e33810663afb9d41be8a7dfd0bca77c063/Gu.Wpf.DataGrid2D/Gu.Wpf.DataGrid2D.csproj

Line in question:

<_NetStandardNuGetPackageFoldersNoSlash Include="$([System.IO.Path]::GetDirectoryName('%(_NetStandardReferences.Identity)'))" />

Annotations are lost with Microsoft.NETCore.App.Ref 3.1.0

string.IsNullOrEmpty no longer gets annotated when switching from 3.0.0 to 3.1.0.

  <PropertyGroup>
    <AnnotatedReferenceAssemblyVersion>3.1.0</AnnotatedReferenceAssemblyVersion>
  </PropertyGroup>
  <ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.0' and '$(MSBuildProjectExtension)' == '.csproj'">
    <PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.97" PrivateAssets="all" />
    <PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[$(AnnotatedReferenceAssemblyVersion)]" />
  </ItemGroup>

Remove [DisallowNull] on IEqualityComparer<T>.GetHashCode

These [DisallowNull] attributes should be removed:

  • IEqualityComparer<T>.GetHashCode(T)
  • EqualityComparer<T>.GetHashCode(T)

The following scenarios are impacted:

  • For netcoreapp3.0 and newer targets, the reference assemblies should be rewritten to remove the existing attribute from the reference assembly
  • For earlier targets, the attributes should simply not be added during the rewrite process

NoWarn doesn't suppress RA1000

A net35 project that uses System.Data will cause a RA1000 warning. Since there's nothing I can do about thisβ€”nothing under my control is misconfiguredβ€”I tried acknowledging the warning by adding <NoWarn>RA1000</NoWarn> to the project.

It had no effect since by default the list is passed to csc which has nothing to do with this, but I'm interested in some way of suppressing it. I know that other SDK targets like NuGet stuff respect NoWarn. Is that what should happen here?

MemberNotNull and MemberNotNullWhen

The two attributes named in the title have been added to C# 9. I presume these can be added to the list for use in projects, same as all the others.

The AnnotatorBuildTask task failed unexpectedly

Severity	Code	Description	Project	File	Line	Suppression State
Error	MSB4018	The "AnnotatorBuildTask" task failed unexpectedly.
System.IO.IOException: The process cannot access the file 'C:\Git\_GuOrg\Gu.Wpf.UiAutomation\Gu.Wpf.UiAutomation\obj\Debug\net45\annotated\mscorlib.dll' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
   at TunnelVisionLabs.ReferenceAssemblyAnnotator.Program.Main(Nullable`1 log, String referenceAssembly, String annotatedReferenceAssembly, String outputAssembly)
   at TunnelVisionLabs.ReferenceAssemblyAnnotator.AnnotatorBuildTask.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	Gu.Wpf.UiAutomation	C:\Users\ds2346\.nuget\packages\tunnelvisionlabs.referenceassemblyannotator\1.0.0-alpha.77\build\TunnelVisionLabs.ReferenceAssemblyAnnotator.targets	60	

From the name I'm guessing it can be something in this nice package.
Repro in this commit https://github.com/GuOrg/Gu.Wpf.UiAutomation/tree/a5b789bf37742a9edd098d187d8a8362a80e43a8

I think I have only seen it after git clean and start Visual Studio

SocketAsyncEventArgs.Completed event nullability is incorrectly written

ReferenceAssemblyAnnotator creates SocketAsyncEventArgs.Completed with a bizarre nullable event args parameter:

image

No diagnostic should be shown here. When compiling on net6.0, there is no diagnostic for this sample code.

I decompiled %userprofile\.nuget\packages\microsoft.netcore.app.ref\6.0.0\ref\net6.0\System.Net.Sockets.dll and confirmed that it has public event EventHandler<SocketAsyncEventArgs>? Completed;, not public event EventHandler<SocketAsyncEventArgs?>? Completed;.

Repro

using System.Net.Sockets;

var x = new SocketAsyncEventArgs();

// ⚠️ CS8622 Nullability of reference types in type of parameter 'e' of 'void OnCompleted(object? sender,
// SocketAsyncEventArgs e)' doesn't match the target delegate 'EventHandler<SocketAsyncEventArgs?>' (possibly
// because of nullability attributes).
//             ↓↓↓↓↓↓↓↓↓↓↓
x.Completed += OnCompleted;

void OnCompleted(object? sender, SocketAsyncEventArgs e)
{
}
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net48</TargetFramework>
    <Nullable>enable</Nullable>
    <LangVersion>11</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" />
    <PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[6.0.0]" />
  </ItemGroup>

</Project>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.