Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Breaks with multiple framework targets #92

Open
ds5678 opened this issue Apr 19, 2022 · 2 comments
Open

[Bug]: Breaks with multiple framework targets #92

ds5678 opened this issue Apr 19, 2022 · 2 comments

Comments

@ds5678
Copy link

ds5678 commented Apr 19, 2022

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
Copy link

R2D221 commented Jan 7, 2023

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
Copy link
Author

ds5678 commented Jan 7, 2023

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

  • Nullable is a polyfill for nullable attributes.
  • PolySharp is a polyfill for many classes, including nullable attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants