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

Transitive dependency on a project.json project treated as ProjectReference #922

Open
mishra14 opened this issue Feb 27, 2017 · 9 comments
Milestone

Comments

@mishra14
Copy link
Contributor

mishra14 commented Feb 27, 2017

Setup -

  • git clone https://github.com/mishra14/dotnetsdkerror
  • Open ConsoleApp15.sln on VS2017
  • Clean solution
  • Restore nuget packages for the solution
  • Build solution

Expected -

Solution builds successfully

Actual -

VS throws an error -

1>------ Build started: Project: ClassLibrary1, Configuration: Debug Any CPU ------
1>  ClassLibrary1 -> E:\dotnetsdkerror\ClassLibrary1\bin\Debug\ClassLibrary1.dll
2>------ Build started: Project: ClassLibrary2, Configuration: Debug Any CPU ------
2>  ClassLibrary2 -> E:\dotnetsdkerror\ClassLibrary2\bin\Debug\ClassLibrary2.dll
3>------ Build started: Project: ConsoleApp15, Configuration: Debug Any CPU ------
3>E:\dotnetsdkerror\ClassLibrary1\project.json(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
3>Done building project "project.json" -- FAILED.
========== Build: 2 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Details about solution -

  • The solution has 3 projects - ConsoleApp15 (net core project targeting net46), ClassLibrary1 and ClassLibrary2 (Both are csproj + project.json projects targeting net46)
  • ConsoleApp15 References -> ClassLibrary2. ClassLibrary2 References -> ClassLibrary1

Workaround -

If I add an extra reference from ConsoleApp15 to ClassLibrary1, the solution builds fine. This indicates that something is wrong when pulling in the msbuildpath a references project!

Notes -

  • VS Version - VS2017 26222.0 d15Rel
  • repros when I build from developer command prompt as well
@mishra14
Copy link
Contributor Author

If we change the path variable in the ConsoleApp15's asset file in the libraries section to point to ClassLibrary1.csproj then it works fine -

Original (fails)-

  "libraries": {
    "ClassLibrary1/1.0.0": {
      "type": "project",
      "path": "../ClassLibrary1/project.json",
      "msbuildProject": "../ClassLibrary1/ClassLibrary1.csproj"
    },

After changing (Builds) -

  "libraries": {
    "ClassLibrary1/1.0.0": {
      "type": "project",
      "path": "../ClassLibrary1/ClassLibrary1.csproj",
      "msbuildProject": "../ClassLibrary1/ClassLibrary1.csproj"
    },

@mishra14
Copy link
Contributor Author

@rainersigwald
Copy link
Member

The error arises when _GetProjectReferenceTargetFrameworkProperties MSBuild's the @(_MSBuildProjectReferenceExistent) item.

Target "_GetProjectReferenceTargetFrameworkProperties: (TargetId:36)" in file "C:\Program Files\dotnet\sdk\1.0.0\Microsoft.Common.CurrentVersion.targets" from project "S:\work\dotnetsdkerror\ConsoleApp15\ConsoleApp15.csproj" (target "PrepareProjectReferences" depends on it):
Building target "_GetProjectReferenceTargetFrameworkProperties" completely.
No input files were specified.
Set Property: ReferringTargetFrameworkForProjectReferences=.NETFramework,Version=v4.6
Task "MSBuild" (TaskId:17)
  Task Parameter:Projects=../ClassLibrary1/project.json (TaskId:17)

It's in that list because it's included here, resulting in

Added Item(s): 
    _TransitiveProjectReferences=
        ../ClassLibrary1/project.json
                ResolvedPath=S:\work\dotnetsdkerror\ConsoleApp15\ClassLibrary1\ClassLibrary1.csproj
Done building target "_ComputeTransitiveProjectReferences" in project "ConsoleApp15.csproj".: (TargetId:28)
Target "IncludeTransitiveProjectReferences: (TargetId:29)" in file "C:\Program Files\dotnet\sdk\1.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets" from project "S:\work\dotnetsdkerror\ConsoleApp15\ConsoleApp15.csproj" (target "ResolvePackageDependenciesForBuild" depends on it):
Added Item(s): 
    ProjectReference=
        ../ClassLibrary1/project.json
                OutputItemType=
                ReferenceSourceTarget=ProjectReference
                ResolvedPath=S:\work\dotnetsdkerror\ConsoleApp15\ClassLibrary1\ClassLibrary1.csproj
                Targets=
Done building target "IncludeTransitiveProjectReferences" in project "ConsoleApp15.csproj".: (TargetId:29)

Maybe it should be

<ProjectReference Include="@(_TransitiveProjectReferences->'%(ResolvedPath)')" />

instead?

@nguerrera
Copy link
Contributor

@natidea on this. So the bug is when the transitive project references kick in and there are SDK -> project.json refs involved, correct?

@natidea
Copy link
Contributor

natidea commented Feb 27, 2017

ResolvedPath is not currently correct for ProjectReferences because of bug #479

@rainersigwald rainersigwald changed the title msbuild/dotnet sdk treating project.json as an xml artifacts when pulling in 2 level reference Transitive dependency on a project.json project treated as ProjectReference Feb 27, 2017
@livarcocc livarcocc added this to the 2.0 M1 milestone Apr 19, 2017
@livarcocc livarcocc modified the milestones: 2.1.0, 2.2.0 May 25, 2017
@ptsoccer
Copy link

I'm kind of curious how this hasn't gotten more attention. Is this not a use case that was expected? I am trying to make a cross platform application and one of these platforms is a full .NET WPF application, and it seems like no matter what I do I am getting screwed by one issue or another.

I am currently on VS 2015 and nuget doesn't handle transitive .NET standard dependencies in legacy projects, so I get runtime errors (NuGet/Home#4488). The only workaround requires me to upgrade to the new project format and VS 2017, which would have been fine, except for this issue. The only workaround here seems to be to flatten the dependency tree, which I suppose is better than my current predicament since now I'll get compile errors instead of runtime errors. Now I would have to spend time upgrading all of the project formats, implement the nuget transitive dependency workaround, and then also implement this workaround. This definitely inspires confidence in the platform.

@nguerrera
Copy link
Contributor

I would suggest switching all projects to PackageReference after moving to VS 2017. It works with non SDK projects too.

@nguerrera
Copy link
Contributor

Also #479 is closed so this may be fixed can you try using the .net core 2.1 preview 2 sdk?

@ptsoccer
Copy link

I tried again to upgrade all the projects to the new format and that seems to have fixed at least this issue. I'm not sure what was different last time (maybe I left some projects unconverted), it seems this only affects project.json projects, so not surprisingly updating to the new format wouldn't have issues.

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

- Microsoft.AspNetCore.Mvc.Analyzers - 3.0.0-rc1.19430.5
- Microsoft.AspNetCore.Mvc.Api.Analyzers - 3.0.0-rc1.19430.5
- Microsoft.AspNetCore.Analyzers - 3.0.0-rc1.19430.5
- Microsoft.AspNetCore.Components.Analyzers - 3.0.0-rc1.19430.5
@marcpopMSFT marcpopMSFT modified the milestones: 2.3.0, Backlog Aug 27, 2021
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

7 participants