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

Runtime-specific build fails for projects with P2P references #696

Closed
blackdwarf opened this issue Jan 20, 2017 · 26 comments
Closed

Runtime-specific build fails for projects with P2P references #696

blackdwarf opened this issue Jan 20, 2017 · 26 comments

Comments

@blackdwarf
Copy link

[ Moved from dotnet/cli#4992 ]

Steps to reproduce

test_app.zip
in test_app\App:

  • dotnet restore
  • dotnet build -r win10-x64

Expected behavior

build succeeds

Actual behavior

build fails with output:

C:\Users\svbomer\AppData\Local\Temp\.NETStandard,Version=v1.4.AssemblyAttributes.cs(4,20): error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(6,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(7,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(8,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(9,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(10,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(11,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(12,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(13,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(14,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
C:\Users\svbomer\AppData\Local\Temp\.NETStandard,Version=v1.4.AssemblyAttributes.cs(4,71): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
C:\Users\svbomer\AppData\Local\Temp\.NETStandard,Version=v1.4.AssemblyAttributes.cs(4,100): error CS0246: The type or namespace name 'FrameworkDisplayName' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
C:\Users\svbomer\AppData\Local\Temp\.NETStandard,Version=v1.4.AssemblyAttributes.cs(4,123): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(6,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(7,61): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(8,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(9,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(10,68): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(11,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(12,53): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(13,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(14,63): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
Library.cs(1,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
C:\Users\svbomer\AppData\Local\Temp\.NETStandard,Version=v1.4.AssemblyAttributes.cs(2,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
C:\Users\svbomer\AppData\Local\Temp\.NETStandard,Version=v1.4.AssemblyAttributes.cs(3,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(3,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
obj\Debug\netstandard1.4\Library.AssemblyInfo.cs(4,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
Library.cs(30,7): error CS0518: Predefined type 'System.Object' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
Library.cs(3,14): error CS0518: Predefined type 'System.Object' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
Library.cs(19,12): error CS0518: Predefined type 'System.Int32' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
Library.cs(24,24): error CS0518: Predefined type 'System.Int32' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
Library.cs(24,12): error CS0518: Predefined type 'System.Void' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]Library.cs(5,13): error CS0518: Predefined type 'System.Int32' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]Library.cs(6,13): error CS0518: Predefined type 'System.Int32' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]Library.cs(8,5): error CS0518: Predefined type 'System.Void' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
Library.cs(14,20): error CS0518: Predefined type 'System.Int32' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
Library.cs(14,5): error CS0518: Predefined type 'System.Void' is not defined or imported [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj] D:\cli\artifacts\win10-x64\stage2\sdk\1.0.0-preview5-004233\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(82,5): error : Assets file 'C:\Users\svbomer\active\projects\managed_linker\test_app\Library\obj\project.assets.json' doesn't have a target for '.NETStandard,Version=v1.4/win10-x64'. Ensure you have restored this project for TargetFramework='netstandard1.4' and RuntimeIdentifier='win10-x64'. [C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj]
D:\cli\artifacts\win10-x64\stage2\sdk\1.0.0-preview5-004233\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(82,5): error : Cannot find project info for 'C:\Users\svbomer\active\projects\managed_linker\test_app\Library\Library.csproj'. This can indicate a missing project reference. [C:\Users\svbomer\active\projects\managed_linker\test_app\App\test_app.csproj]

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview5-004233)

Product Information:
 Version:            1.0.0-preview5-004233
 Commit SHA-1 hash:  1fd99f1588

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   D:\cli\artifacts\win10-x64\stage2\sdk\1.0.0-preview5-004233
@dasMulli
Copy link
Contributor

Jus repro'd it with csproj files compatible with the new implicit items:
repro.zip
Reproduces with CLI versions 1.0.0-rc4-004598 as well as 1.0.0-rc3-004517. (run dotnet restore and dotnet publish -r win7-x64 in the App directory)

This currently prevents creating self-contained applications that reference a library project.
Is this scenario expected to work in RC3? cc @dsplaisted @nguerrera

@srivatsn
Copy link
Contributor

Is this the same as #527? @nguerrera

@srivatsn srivatsn assigned nguerrera and unassigned dsplaisted Jan 27, 2017
@srivatsn srivatsn added this to the 1.0 RTM milestone Jan 27, 2017
@AlgorithmsAreCool
Copy link

I attempted an upgrade to RC3 on my project and ran into this issue. Is a short term fix anticipated or should I roll back until later?

@dasMulli
Copy link
Contributor

dasMulli commented Jan 30, 2017

The problem seems to be that when dotnet build -r some-RID sets RuntimeIdentifier, this is also passed along to referenced projects. If a referenced project has not been restored for a runtime (like a library project), this fails with the following error:

…/1.0.0-rc3-004530/…/Microsoft.NET.Sdk.targets(76,5): error :
 Assets file '…' doesn't have a target for '.NETStandard,Version=v1.4/win10-x64'. 
Ensure you have restored this project for TargetFramework='netstandard1.4' and RuntimeIdentifier='win10-x64'. […/Lib/Lib.csproj]

@AlgorithmsAreCool Since I don't know a simple way to unset properties (is there any?), the only way I could make this work is by using and intermediate property:
Use dotnet build /p:AppRuntimeIdentifier=win10-x64 to build.
In the main application's csproj file:

<PropertyGroup>
  <RuntimeIdentifier>$(AppRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>

@srivatsn I don't think this is related to #527

@srivatsn
Copy link
Contributor

srivatsn commented Jan 30, 2017

Interesting. @DustinCampbell was talking about this issue as well. I suspect the fix needs to be a mix of CLI and SDK similar to what you've done. The CLI should set /p:RequestedRuntimeIdentifier or some such property and have the SDK apply it to a project only if it's "applicable". We'll need the same thing for -f as well.

@piotrpMSFT @livarcocc thoughts?

@DustinCampbell
Copy link
Member

Yes, we need to fix this. Per our hallway conversation, we should do the same thing for TargetFramework as well. This becomes a significant problem when trying dotnet build an .sln file.

@nguerrera
Copy link
Contributor

@rainersigwald

@rainersigwald
Copy link
Member

Yes, setting a property at the command line overrides all projects that build in that invocation. Having an EntryPointRuntimeIdentifier or something similar sounds reasonable (albeit as another concept people have to know about).

@DustinCampbell
Copy link
Member

@rainersigwald: I you recall, this is the thing you and I chatted about last Friday.

I don't think it's actually another concept. From the user perspective, MSBuild will do the thing it's always done. If you set RuntimeIdentifier or TargetFramework globally, it's applied globally. However, from the perspective of the CLI, setting the "--framework" or "--runtime" properties during "dotnet build" can be a bit smarter and do what the user very likely expects to happen.

@rainersigwald
Copy link
Member

Yeah, it makes sense once you know the details--but understanding that dotnet build --runtime Whatever is more than just sugar over MSBuild /p:Runtime=Whatever is required. Still think it's the right thing to do.

If we had more time I might recommend renaming the inner per-project property to be a bit more esoteric and renaming the outer "overall requested" property to more closely match the CLI command line param . . . but that's a nit.

@dasMulli
Copy link
Contributor

So, what I would expect to happen:
For all projects that specify RuntimeIdentifiers, it sets RuntimeIdentifier if not already set.
I guess it would look sth like:

<RuntimeIdentifier Condition=" '$(RuntimeIdentifier)' == '' and '$(EntryPointRuntimeIdentifier)' != '' and '$(RuntimeIdentifiers)' != '' ">$(EntryPointRuntimeIdentifier)</RuntimeIdentifier>

It should be possible to reference RID-specific and RID-agnostic projects that way.

If we had more time I might recommend renaming …

@rainersigwald Since this will (and should) probably stick around for at least a decade or two, I'd like there to be a proper naming strategy ❤️

@nguerrera
Copy link
Contributor

@srivatsn @piotrpMSFT Since this issue is separate from the other RID issues on my plate and time is of the essence could someone else drive this into CLI + SDK?

@DustinCampbell
Copy link
Member

@rainersigwald:

Yeah, it makes sense once you know the details--but understanding that dotnet build --runtime Whatever is more than just sugar over MSBuild /p:Runtime=Whatever is required. Still think it's the right thing to do.

That's fair, but people probably shouldn't be thinking of dotnet build as sugar over MSBuild. If that's all it were, there isn't much value from a CLI UI perspective.

@AlgorithmsAreCool
Copy link

I was able to work around my issue with by making the restore -r <RID> step explicit in my build pipeline for now.

@srivatsn
Copy link
Contributor

srivatsn commented Feb 1, 2017

@piotrpMSFT has graciously offered to help out with this. Assigning to Peter.

@srivatsn srivatsn assigned TheRealPiotrP and unassigned nguerrera Feb 1, 2017
@srivatsn srivatsn added the Bug label Feb 1, 2017
@niemyjski
Copy link

I'm also hitting this when trying to upgrade foundatio: https://github.com/exceptionless/foundatio/tree/feature/dotnet

@AlgorithmsAreCool
Copy link

@niemyjski are you specifying an RID when you build or publish? If so have you tried adding a dotnet restore -r <RID> step just before your build/publish in your build script?

@TheRealPiotrP
Copy link
Contributor

Starting to take a look at this. Per @DustinCampbell's point, we want to address both:

  1. Specify -r for a root project whose P2P dependencies are not RID specific
  2. Specify -f or -r for a solution for which only some projects support that TFM or RID

Having looked at the SDK a bit, I'm less convinced now that the solution to these problems will be unified. This issue may end up being split into two, where we will want to fix both. More info to come.

@TheRealPiotrP
Copy link
Contributor

odd. I just tried @dasMulli's repro on CLI 1.0.0-rc4-004748 on osx with -r osx.10.11-x64 and the publish operation was successful, producing what seems to be a working self contained app. I'll try this again on Windows when in the office tomorrow. Going to lok at -f for now.

@dasMulli
Copy link
Contributor

dasMulli commented Feb 2, 2017

@piotrpMSFT really odd.. it repros with both 1.0.0-rc4-004748 and 1.0.0-rc4-004755 on my Mac 😕

@dasMulli
Copy link
Contributor

dasMulli commented Feb 2, 2017

Another workaround that works is to reference the library with:

<ProjectReference Include="..\Lib\Lib.csproj" Properties="RuntimeIdentifier=" />

This would be easier to do with an update item from the SDK but I haven't explored what the effects are - probably loosing RID-specific items from projects. (did this ever work in project.json? RID-specific libraries?)

@niemyjski
Copy link

@AlgorithmsAreCool Nope, no rids at all.

@TheRealPiotrP
Copy link
Contributor

Just thought I'd share that PR #828 should address the RID issue and does not introduce any new user gestures or concepts. We were able to keep the alternate property name as an internal contract between Referring projects and Referenced projects.

I'm trying a similar approach with the build sln -f issue... though that is proving considerably more involved.

@niemyjski
Copy link

@TheRealPiotrP
Copy link
Contributor

No, it's not merged yet. I hope to have a CLI that exhibits this behavior available this week, however. Since -r is mostly a command-line consideration, this should unblock most affected folks.

The change impacts a lot of repos, so merging it will be a full-day dance I'm afraid.

@srivatsn
Copy link
Contributor

Fixed with #836

mmitche pushed a commit to mmitche/sdk that referenced this issue Jun 5, 2020
…0190606.7 (dotnet#696)

- Microsoft.AspNetCore.Mvc.Api.Analyzers - 3.0.0-preview7.19306.7
- Microsoft.AspNetCore.Mvc.Analyzers - 3.0.0-preview7.19306.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants