Core: 3.0 preview8 - Build failure with Directory.props and user secrets

Created on 2 Sep 2019  路  12Comments  路  Source: dotnet/core

3.0 preview8 - Build failure with Directory.props and user secrets

3.0 preview8 sdk is unable to build some assemblies because the generated assmblyinfo.cs is throwing error CS0234 .

The exact build runs successfully when core 2.2 sdk.

General

3.0 preview8 sdk is unable to build some assemblies because the generated assmblyinfo.cs is throwing error. Some properties are copied from Directory.Build.props.

line:
_[assembly: Microsoft.Extensions.Configuration.UserSecrets.UserSecretsIdAttribute("secrets_file")]_

error:
_Error CS0234 The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)_

While building this library with 2.2 it runs successfully (not sure for preview versions between), preview8.0 fails to build.

All 12 comments

@livarcocc or @nguerrera - any troubleshooting suggestions?

It is possible the namespace has moved from 2.2 to 3.0 on ASP.NET's side.

@mkArtakMSFT would you know?

Adding @Tratcher in case he has some contest here.

The SDK semi-blindly emits the attribute if UserSecretsId is set in the project, so if that is imported in a Directory.Build.props for a project that does not use the asp.net core shared framework or references the right packages, this will likely cause this issue.

See https://github.com/dotnet/sdk/blob/f16d813fa5671eea294073b76ef9019081034306/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets#L311-L337

cc @dsplaisted

This would be a breaking change in 3.0 SDK.

@BrunoDrljanovcan Can you share an example of a project that is failing to build with the updated sdk, or a binlog of the failing build?

This is super easy to isolate:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UserSecretsId>foo</UserSecretsId>
  </PropertyGroup>

</Project>
obj\Debug\netcoreapp3.0\testcons.AssemblyInfo.cs(14,22): error CS0234: The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\demos\testcons\testcons.csproj]

Happens for any ~3.0~ project that does not provide a type for Microsoft.Extensions.Configuration.UserSecrets.UserSecretsIdAttribute.

Just that for the OP the UserSecretsId was set via a Directory.Build.props.

It's pretty much what @dasMulli wrote here. Although TargetFramework is netcoreapp2.2.

Relevant comment on PR when this was added: https://github.com/dotnet/sdk/pull/2774/files#r247013838

This will be fixed in 3.1.

It has also been added to the list of known issues for the .NET Core 3.0 SDK: https://github.com/dotnet/core/blob/master/release-notes/3.0/3.0-known-issues.md

Was this page helpful?
0 / 5 - 0 ratings