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

Issues because ThisAssembly is not public #92

Closed
FionaHolder opened this issue Mar 21, 2019 · 10 comments
Closed

Issues because ThisAssembly is not public #92

FionaHolder opened this issue Mar 21, 2019 · 10 comments
Labels
bydesign The feature works as designed

Comments

@FionaHolder
Copy link

I've added this to my ASP.NET Core 2.2 project and it all works fine and builds etc.

However, when I try to do any scaffolding in the solution, it breaks.

I go to add a scaffolded item:

image

...and I get this error:

image

It's presumably something to do with how the scaffolding build is configured, but that seems out of my control.

@bhutch29
Copy link

Interestingly, i found this issue because in a C# solution I maintain a freshly cloned local copy fails to build due to "ThisAssembly is inaccessible due to its protection level" error in every project that depends on the GitInfo Nuget package. I was able to fix it by doing a nuget restore manually, but Visual Studio's automatic "restore before build" functionality did not solve it.

@kzu
Copy link
Member

kzu commented Oct 15, 2019

Since the ThisAssembly class is partial (on purpose), you can make it public by just declaring it so in another file:

public partial class ThisAssembly { }

(make sure the namespace matches)

See https://github.com/kzu/GitInfo/blob/master/src/GitInfo/build/GitInfo.cs.pp#L30

@kzu kzu closed this as completed Oct 15, 2019
@kzu kzu added the bydesign The feature works as designed label Oct 15, 2019
@watfordgnf
Copy link

We found that if you are precompiling ASP.Net MVC/Web Forms there is an extra step which produces an AssemblyInfo.dll file. This step only uses AssemblyInfo.cs and will ignore any public partial class ThisAssembly you may place anywhere. We had to go with the strategy given in this StackOverflow answer to make this work, where you remove all assembly attributes which reference ThisAssembly from your AssemblyInfo.cs and move them into another file.

@kzu
Copy link
Member

kzu commented Feb 22, 2020

could you provide a binlog so I can see what steps are missing? Please use a clean repro project, not an actual one, since the binlog can contain private information.

@watfordgnf
Copy link

I'm not sure I can binlog that ASP.Net step, but I'll look into that.

@rmarinho
Copy link

I m hitting this :( i think this might be related of having GitInfo in several projects, and one projects wants to use ThisAssembly from other project..

Make it public doesn't work. Any other ideas ?!

@kzu
Copy link
Member

kzu commented Jan 14, 2021

@rmarinho that's quite vague and not very actionable. Care to elaborate, provide a repro or a binlog perhaps? It looks like you have a different issue than the one described here

@rmarinho
Copy link

Hi @kzu sorry :)

So i have a sln with several projects.. I added GitInfo like this:

my Directory.Build.props

<Project>
  <Import Project="GitVersion.props" />
  <Target Name="GitVersion" />
</Project>

my GitVersion.props

<Project>

	<PropertyGroup>
		<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
		<GitIgnoreTagVersion>True</GitIgnoreTagVersion>
		<GitIgnoreBranchVersion>True</GitIgnoreBranchVersion>
		<GitThisAssembly>False</GitThisAssembly>
	</PropertyGroup>

	<ItemGroup>
		<PackageReference Include="GitInfo" Version="2.0.11" PrivateAssets="All" />
	</ItemGroup>

	<Target Name="SetAssemblyInfoVersions" AfterTargets="PrepareForBuild" BeforeTargets="GenerateAssemblyInfo" DependsOnTargets="GitVersion">
		<PropertyGroup>
			<AssemblyVersion Condition="'$(AssemblyVersion)' == ''">$(GitBaseVersionMajor).$(GitBaseVersionMinor).0.0</AssemblyVersion>
			<FileVersion Condition="'$(FileVersion)' == ''">$(GitBaseVersionMajor).$(GitBaseVersionMinor).$(GitBaseVersionPatch).$(GitCommits)</FileVersion>
			<InformationalVersion Condition="'$(InformationalVersion)' == '' And '$(GitCommits)' == '0'">$(GitBaseVersionMajor).$(GitBaseVersionMinor).$(GitBaseVersionPatch)$(GitSemVerDashLabel)+sha.$(GitCommit)</InformationalVersion>
			<InformationalVersion Condition="'$(InformationalVersion)' == '' And '$(GitCommits)' != '0'">$(GitBaseVersionMajor).$(GitBaseVersionMinor).$(GitBaseVersionPatch).$(GitCommits)$(GitSemVerDashLabel)+sha.$(GitCommit)</InformationalVersion>
		</PropertyGroup>
	</Target>

	<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec" DependsOnTargets="GitVersion">
		<PropertyGroup>
			<PackageVersion>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)</PackageVersion>
			<NuspecProperties>configuration=$(Configuration);version=$(PackageVersion)</NuspecProperties>
		</PropertyGroup>
	</Target>

</Project>

So one of my projects uses something like this:

public const string HookVersion = "v" + ThisAssembly.Git.SemVer.Major; 

When i try to build

C:\Xamarin\Xamarin.Forms.Build\XFTool>dotnet build XFTool.csproj /bl
Microsoft (R) Build Engine version 16.8.0-preview-20417-01+df645299a for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files\dotnet\sdk\6.0.100-alpha.1.20421.6\MSBuild.dll -consoleloggerparameters:Summary -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\6.0.100-alpha.1.20421.6\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\6.0.100-alpha.1.20421.6\dotnet.dll -maxcpucount -restore -verbosity:m /bl XFTool.csproj
  Determining projects to restore...
  All projects are up-to-date for restore.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  XF.Models -> C:\Xamarin\Xamarin.Forms.Build\XF.Models\bin\Debug\netstandard2.1\XF.Models.dll
C:\Xamarin\Xamarin.Forms.Build\XF.Services\Helpers\Constants.cs(17,43): error CS0122: 'ThisAssembly' is inaccessible due to its protection level [C:\Xamarin\Xamarin.Forms.Build\XF.Services\XF.Services.csproj]

Build FAILED.

C:\Xamarin\Xamarin.Forms.Build\XF.Services\Helpers\Constants.cs(17,43): error CS0122: 'ThisAssembly' is inaccessible due to its protection level [C:\Xamarin\Xamarin.Forms.Build\XF.Services\XF.Services.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:03.23

So i have a binlog too , thanks!
msbuild.zip

@kzu
Copy link
Member

kzu commented Jan 14, 2021

So, you set <GitThisAssembly>False</GitThisAssembly> and expect ThisAssembly to be generated? I don't understand :)

@rmarinho
Copy link

Dahhh .. thanks Daniel .. that's what copy paste does to us .. :P

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bydesign The feature works as designed
Projects
None yet
Development

No branches or pull requests

5 participants