tunnelvisionlabs / ReferenceAssemblyAnnotator

IL weaver to add nullability annotations to .NET reference assemblies
MIT License
71 stars 8 forks source link

[Bug]: Breaks with multiple framework targets #92

Open ds5678 opened 2 years ago

ds5678 commented 2 years ago

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'">
R2D221 commented 1 year ago

Not sure how useful it will be here, but I never had this problem because I added the dependency only for the frameworks who need it.

Like so:

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
  <PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  </PackageReference>
  <PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[7.0.0]" />
</ItemGroup>
ds5678 commented 1 year ago

@R2D221 thank you for the recommendation. Unfortunately, I have moved on from this repository. I have used the following alternatives in other projects: