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

ResolvePackageDependencies produces invalid ResolvedPath for <ProjectReference .../> #1435

Closed
BrunoJuchli opened this issue Jul 21, 2017 · 2 comments

Comments

@BrunoJuchli
Copy link
Contributor

BrunoJuchli commented Jul 21, 2017

Running on latest previews (VS2017.3 Preview 4, .net sdk 2.0.0-preview2-006497) my build fails because the ResolvePackageDependencies Task produces invalid results / output. I'm building from within VS.

In short, a path included in @(PackageDefinitions->'%(ResolvedPath)' is wrong. Here is the actual vs the expected path:

C:\Development\StaticProxy.Fody.VS2017\IntegrationTests\StaticProxy.Fody\StaticProxy.Fody.csproj
C:\Development\StaticProxy.Fody.VS2017\StaticProxy.Fody\StaticProxy.Fody.csproj

The actual path does not exist, that's why a consumer of this path fails.

The complete output for that particular PackageDefinition (which results from a <ProjectReference Include="..\StaticProxy.Fody\StaticProxy.Fody.csproj" />) is:

2> StaticProxy.Fody/1.0.0
2> Name=StaticProxy.Fody
2> Path=../StaticProxy.Fody/StaticProxy.Fody.csproj
2> ResolvedPath=C:\Development\StaticProxy.Fody.VS2017\IntegrationTests\StaticProxy.Fody\StaticProxy.Fody.csproj
2> Type=project
2> Version=1.0.0

Excerpts from the *.csproj of the project (targeting net462) follows, but I would like to mention that some of the projects in the solution actualy do target netstandard - don't know if that makes a difference?

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
	<TargetFrameworks>net462</TargetFrameworks>
  </PropertyGroup>
  <ItemGroup>
	<Reference Include="System" />
	...
	<PackageReference Include="Castle.Core" Version="4.1.1" />
	...
  </ItemGroup>
  ...
  <ItemGroup>
	<ProjectReference Include="..\StaticProxy.Fody\StaticProxy.Fody.csproj" />
  </ItemGroup>
</Project>

Link to project: https://github.com/BrunoJuchli/StaticProxy.Fody/tree/7d8b924d90759cb3248803514ba631463358494a/

Diagnostic MSBuild Log: https://gist.github.com/BrunoJuchli/c5c8b5e74571cbaa99e8e8e5997acaf3/raw/9bc0f0bd94cd77ccf0cbfb58bf66982dfca961bb/MsBuildLog.txt

@BrunoJuchli
Copy link
Contributor Author

BrunoJuchli commented Jul 21, 2017

The task receives:

ProjectAssetsFile=C:\Development\StaticProxy.Fody.VS2017\IntegrationTests\obj\project.assets.json
ProjectPath=C:\Development\StaticProxy.Fody.VS2017\IntegrationTests\IntegrationTests.csproj

GetAbsolutePathFromProjectRelativePath(package.MSBuildProject) is called and performs this:

return Path.GetFullPath(
               Path.Combine(
                   Path.GetDirectoryName(
                          Path.GetFullPath(ProjectAssetsFile))
                   , path));

The result of this call is then set as the ResolvedPath metadata.

Based on my observed result (C:\Development\StaticProxy.Fody.VS2017\IntegrationTests\StaticProxy.Fody\StaticProxy.Fody.csproj) I deduct that path must be (the same as specified in the csproj): ..\StaticProxy.Fody\StaticProxy.Fody.csproj.

The path in the csproj is relative to the location of the csproj.
Is there any reason there should be some Voodoo-magic involved rebasing all paths to the location of the ProjectAssetsFile? It seems (unnecessarily) complicated.
So my guess is that that's where the bug lies.

Which means the implementation should be changed to:

return Path.GetFullPath(
               Path.Combine(
                   Path.GetDirectoryName(ProjectPath)
                   , path));

I removed the second Path.GetFullPath call as - at least in my scenario - the Task already received the ProjectPath as FullPath. Is this always the case?

BrunoJuchli added a commit to BrunoJuchli/sdk that referenced this issue Jul 21, 2017
See dotnet#1435 for error description and analysis of the problem.

Questions:
 - Is it actually the desired outcome that ResolvedPath points to the csproj file? Or should it point to the output directory of that project?
 - Is ProjectPath always passed in as full path? (otherwise it needs to be enclosed by a `Path.GetFullPath`)
BrunoJuchli added a commit to BrunoJuchli/sdk that referenced this issue Jul 22, 2017
The old implementation combined the relative `<ProjectReference Include="..." />` path with the directory of the `ProjectAssetFile`.
Corrected this to combine the relative project reference with the current's project path.
@BrunoJuchli
Copy link
Contributor Author

Duplicate of #479

nguerrera added a commit that referenced this issue Oct 30, 2017
Fix #1435 - calculation of ResolvedPath for project references
GangWang01 pushed a commit to GangWang01/sdk that referenced this issue Jun 7, 2022
Merging rel/2.1.0-preview2 into release/2.1
GangWang01 pushed a commit to GangWang01/sdk that referenced this issue Jul 11, 2022
Merging rel/2.1.0-preview2 into release/2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant