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

Project dependency specified in .sln file, causes build to fail, on Unix #1957

Closed
radical opened this issue Apr 7, 2017 · 20 comments
Closed

Comments

@radical
Copy link
Member

radical commented Apr 7, 2017

I have a .sln with:

Projects A, B and C.
A has a ProjectReference to B
B depends on C, specified in the .sln file

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibB", "LibB\LibB.csproj", "{34ED4F6B-145E-467E-AFFB-48B3237878D3}"
        ProjectSection(ProjectDependencies) = postProject
                        {9C743F94-9DA8-422B-8FB8-DEB139216381} = {9C743F94-9DA8-422B-8FB8-DEB139216381}
        EndProjectSection
EndProject

Building this with msbuild:

"/Users/ankit/Projects/SlnProjectDepsBug/SlnProjectDepsBug.sln" (default target) (1) ->
"/Users/ankit/Projects/SlnProjectDepsBug/LibB/LibB.csproj.metaproj" (default target) (5) ->
  /Users/ankit/Projects/SlnProjectDepsBug/LibB/LibB.csproj.metaproj : error MSB4025: The project file could not be loaded. Could not find file "/Users/ankit/Projects/SlnProjectDepsBug/LibB/LibB.csproj.metaproj".

From what I able to gather, the SolutionProjectGenerator creates a ProjectInstance for LibB.csproj.metaproj. When RequestBuilder starts to build the .sln.metaproj and wants to build LibB.csproj.metaproj, it doesn't seem to have access to the earlier ProjectInstance and tries to create a new one, which tries to access the file, but since that was just in-memory, it fails.

If you run it with MSBuildEmitSolution=1 then the LibB.csproj.metaproj is written to disk and the build succeeds.

Also, there is a bug due to which if you use MSBUILDEMITSOLUTION=1 (note the case!), the .sln.metaproj.tmp is written to disk before the .csproj.metaproj has been added to it, so you won't see it there. I'll add open a PR for that.

@radical radical changed the title Project dependency specified in .sln file, causes build to fail. Possibly a regression [REGRESSION] Project dependency specified in .sln file, causes build to fail Apr 7, 2017
@radical
Copy link
Member Author

radical commented Apr 7, 2017

@AndyGerlicher AndyGerlicher added this to the After 15 milestone Apr 13, 2017
@AndyGerlicher
Copy link
Contributor

Team Triage:
Moving this out. @radical you mention this is a regression? Does this behavior work in VS2015 and is broken in VS2017?

@radical
Copy link
Member Author

radical commented Apr 25, 2017

I was mistaken. It doesn't look like a regression. I will investigate why this is happening on mono/mac though.

@radical radical closed this as completed Apr 25, 2017
@radical radical reopened this May 2, 2017
@radical radical changed the title [REGRESSION] Project dependency specified in .sln file, causes build to fail Project dependency specified in .sln file, causes build to fail, on Unix May 2, 2017
radical pushed a commit to mono/msbuild that referenced this issue May 2, 2017
Given a .sln with:

Projects A, B and C.
A has a ProjectReference to B
B depends on C, specified in the .sln file

```
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibB", "LibB\LibB.csproj", "{34ED4F6B-145E-467E-AFFB-48B3237878D3}"
        ProjectSection(ProjectDependencies) = postProject
                        {9C743F94-9DA8-422B-8FB8-DEB139216381} = {9C743F94-9DA8-422B-8FB8-DEB139216381}
        EndProjectSection
EndProject
```

Building this with msbuild:

```
"/Users/ankit/Projects/SlnProjectDepsBug/SlnProjectDepsBug.sln" (default target) (1) ->
"/Users/ankit/Projects/SlnProjectDepsBug/LibB/LibB.csproj.metaproj" (default target) (5) ->
  /Users/ankit/Projects/SlnProjectDepsBug/LibB/LibB.csproj.metaproj : error MSB4025: The project file could not be loaded. Could not find file "/Users/ankit/Projects/SlnProjectDepsBug/LibB/LibB.csproj.metaproj".
```

The solution project generator creates a Project and ProjectInstance for
`LibB.csproj.metaproj`, and a `BuildRequestConfiguration` gets added to
`BuilderManager._configCache` from `LoadSolutionIntoConfiguration`. But it has
a property:

	CurrentSolutionConfigurationContents=<SolutionConfiguration>
		<ProjectConfiguration Project="{2A45AC7E-98A0-4AA8-84F0-7C02A7469313}" AbsolutePath="/Users/ankit/Projects/SlnProjectDepsBug/SlnProjectDepsBug\SlnProjectDepsBug.csproj" BuildProjectInSolution="True">Debug|x86</ProjectConfiguration>
		  <ProjectConfiguration Project="{9C743F94-9DA8-422B-8FB8-DEB139216381}" AbsolutePath="/Users/ankit/Projects/SlnProjectDepsBug/LibC\LibC.csproj" BuildProjectInSolution="True">Debug|AnyCPU</ProjectConfiguration>
		  <ProjectConfiguration Project="{34ED4F6B-145E-467E-AFFB-48B3237878D3}" AbsolutePath="/Users/ankit/Projects/SlnProjectDepsBug/LibB\LibB.csproj" BuildProjectInSolution="True">Debug|AnyCPU<ProjectDependency Project="{9C743F94-9DA8-422B-8FB8-DEB139216381}" /></ProjectConfiguration>
		</SolutionConfiguration>

.. with `LibB\LibB.csproj`.

And at a later point the instance gets looked up from
`BuildRequestEngine.IssueBuildRequests`, and at this point the build
request has the same property but with fixed paths, which causes the
`GetMatchingConfiguration` to fail trying to match the property. IOW, it
fails to find the `ProjectInstance` for `LibB.csproj.metaproj` and so tries
to load the project file instead, which doesn't exist on disk!

`ProjectInSolution.RelativePath` should fix up the project path being read from
the sln file. `ParentSolution.SolutionFileDirectory` is built correctly,
and it's setter is used only by tests. So `ProjectInSolution.AbsolutePath`
doesn't need to be updated.

FIXME: Added a test project but it is not integrated in the build. It
should probably be added in SolutionProjectGenerator_Tests.

(dotnet#1957)
@radical
Copy link
Member Author

radical commented May 2, 2017

I'll open a PR for this in a few days. This is the patch that I am using: mono@4a3d1b1

@jasonsturges
Copy link

jasonsturges commented Sep 1, 2017

Likewise experiencing this issue on Mac - project solution from Visual Studio 2017, errors when built on VS Code.

Solution excerpt:

# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Archive", "Archive\Archive.csproj", "{08C511A8-3F8F-4182-A9C0-7D15262F73A2}"
	ProjectSection(ProjectDependencies) = postProject
		{5E854290-82A9-443D-83A8-BC85354817FD} = {5E854290-82A9-443D-83A8-BC85354817FD}
	EndProjectSection
EndProject

Generates error on build:

Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

/Users/jsturges/Projects/archive-db/Archive/Archive.csproj.metaproj : error MSB4025: The project file could not be loaded. Could not find file '/Users/jsturges/Projects/archive-db/Archive/Archive.csproj.metaproj'.

Build FAILED.

VS Code, Version 1.15.1 (1.15.1) 41abd21
Visual Studio 2017, Version 15.3.3
MS Build: 15.3.409.57025

.Net Core 2.0 project specifying dependency to .Net Standard 2.0 library.

Removing the post project dependency from the .sln file builds without errors.

@bouassaba
Copy link

I have the same issue on Linux when the project dependency is specified in the .sln, I get the following error:

error MSB4025: The project file could not be loaded. Could not find file '/home/user/project/project.csproj.metaproj'.

But it works perfectly on Visual Studio 2017 and Visual Studio for Mac.

Removing the dependency in the .sln fixes the issue on Linux.

I'm using .NET Core 2.0 SDK.

@mahald
Copy link

mahald commented Oct 25, 2017

while
dotnet publish -c Release -o out
is working on windows i had the same problem on linux. For me it got fixed by passing the csproj file like:
dotnet publish -c Release -o out project.csproj
it still builds the entire solution (maybe as in my case the project in project.csproj depends on all other projects)

@Saibamen
Copy link

@AlexandreOuellet
Copy link

AlexandreOuellet commented Nov 15, 2017

My issue is slightly different, but I found a solution that might help you out.

In my Solution.sln, I have 3 csproj :

  • A is standalone
  • B depends upon A
  • C depends upon both B and A

When I do a "dotnet restore", everything is fine, but doing a "dotnet publish ./MySolution.sln -c Release -o ./obj/Docker/publish", it gave me errors about .csproj.metaproj missing. But removing C's dependency on A seems to have fixed the problem.

Not saying this is the best solution (or even feasible in some situation), but I managed to fix it this way on my end.

edit : Just to mention, I'm running on Core 2.0 SDK and Ubuntu 16.04

@AlexandreOuellet
Copy link

AlexandreOuellet commented Nov 15, 2017

To add to my previous fix : It worked for some sln, but not all of them (I don't know why it actually worked, maybe simply touching the csproj made a difference?)

Anyway, the fix is actually what @jasonsturges mentionned : the proper solution to remove the postProject part of your .sln file (anything between ProjectSection and EndProjectSection, including those tags)

@sherlock1982
Copy link

When deps are not specified in a solution file they're all published with a Debug configuration for some reason. When deps are specified than each and every dep requires framework and rid specified in csproj. So both ways are not working properly

@ms0713
Copy link

ms0713 commented Nov 20, 2017

My .net core 2.0 console application runs properly in Windows OS. But I m having problem running it on RHEL7.

In my .sln file, I have 6-7 projects (.Net Stansard Library 2.0). Some projects depends on some other. But my solution file does not contain any word like postProject.

When I run following command, it gives no error and command prompt comes back without doing anything. Also it gives no error or nothing.
$ dotnet AppName.dll 1
1 is command line argument.

My application uses SQL connection, Reflection, Third Party dlls( developed in c++), socket connection etc.

I also tried running a demo application with command line arguments, SQL connection. It works fine in RHEL7.
My application dll has version like 1.2.3.4.
While Publishing my code, it gives target runtime as Portable. But another sample with target runtime as Portable wotks fine in RHEL7.

What could be the problem? If you have any idea regarding this please share.

@forki
Copy link

forki commented Nov 20, 2017

yes deleting /obj during the build fixed it for me

@ctaggart
Copy link

ctaggart commented Dec 25, 2017

I can confirm that the workaround is to manually edit the .sln file and change the paths to use slashes instead of backslashes. The solution will then correctly restore on Windows and Linux. The changes I just made to make Froto.sln restore on Travis CI:

ctaggart/froto@fb2bf7f

This is a bug. We should have to make this change to make it work on Unix.

@damageboy
Copy link

damageboy commented Dec 27, 2017

Same here,
I just add the following POS to my build script:

if [ "$(uname)" == "Linux" ]; then
  echo "Unfucking xxx.sln for ${__BuildOS}"
  sed -i 's#\\#/#g' xxx.sln
fi

@enricosada
Copy link

Same with .net core sdk 2.1.3

rainersigwald added a commit to rainersigwald/msbuild that referenced this issue Feb 7, 2018
rainersigwald added a commit to rainersigwald/msbuild that referenced this issue Feb 7, 2018
@braunsonm
Copy link

Hey @rainersigwald I'm experiencing this issue with dotnet Core, when will your commit be made into a release to resolve the issue?

The suggested sed -i 's#\\#/#g' xxx.sln on linux fixes the build, but the same change on windows will cause the build to fail

@rainersigwald
Copy link
Member

@Chaosca It should be in 2.1-preview2; unfortunately it didn't make -preview1.

@halcwb
Copy link

halcwb commented Apr 27, 2018

This is happening again in my solution first created on mac, then migrated to VS2017. Now when building the solution on macosx again I get the error:

/src/Informedica.GenUtils.Lib/Informedica.GenUtils.Lib.fsproj.metaproj : error MSB4025: The project file could not be loaded. Could not find file 'src/Informedica.GenUtils.Lib/Informedica.GenUtils.Lib.fsproj.metaproj'.

@rainersigwald
Copy link
Member

@halcwb Editing the slashes back to / should keep it working cross-plat until VS overwrites them on save. A fixed .NET Core SDK will be released before too long.

@AR-May AR-May added the triaged label Feb 21, 2024
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