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

ThisAssembly is unusable in old-style NetFX projects. error CS0122: 'ThisAssembly' is inaccessible due to its protection level #301

Closed
ShadowMarker789 opened this issue May 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@ShadowMarker789
Copy link

Describe the Bug

In old-style NetFX WPF csproj projects, any attempt to reference ThisAssembly, even typeof(ThisAssembly) will not compile.

error CS0122: 'ThisAssembly' is inaccessible due to its protection level

Steps to Reproduce

In an old-style NetFX WPF csproj C# file, any references to ThisAssembly will not compile.

public class ReproTest
{
  [Fact]
  public void Repro()
  {
    var branchName = ThisAssembly.Git.Branch; // this won't compile. 
  }
}

Expected Behavior

The expectations were that this would compile.

Exception with Stack Trace

No exception, only a build error placed above.

Version Info

1.4.3 via Nuget

Additional Info

Related issues possibly

dotnet/Nerdbank.GitVersioning#404

dotnet/Nerdbank.GitVersioning#449

@ShadowMarker789 ShadowMarker789 added the bug Something isn't working label May 17, 2024
@kzu
Copy link
Member

kzu commented May 17, 2024

From microsoft/CsWin32#7, is it fixed when you set this property?

<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>

@kzu
Copy link
Member

kzu commented May 17, 2024

Converting the project to SDK-style fixes the issue. I took a clean .NET WPF app from the template, removed all the relevant stuff and with the following content, it works:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <OutputType>WinExe</OutputType>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
    <UseWPF>true</UseWPF>
    <LangVersion>8.0</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xaml">
      <RequiredTargetFramework>4.0</RequiredTargetFramework>
    </Reference>
    <Reference Include="WindowsBase" />
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="ThisAssembly" Version="1.4.3" PrivateAssets="all" />
  </ItemGroup>
</Project>

Legacy projects are unlikely to be supported, but I'd take a PR that adds it.

@kzu kzu closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
@devlooped devlooped locked and limited conversation to collaborators Sep 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants