-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
'dotnet build' assumes "Build Dependencies -> Project Dependencies" are project references #2274
Comments
Moving to msbuild, per @rainersigwald |
TL;DR Solutions files offer the capability of defining build ordering. This is probably obsolete functionality from the time before MSBuild. Here is a sln snippet containing a project dependency:
The above snippet states that MSBuild converts solution files into in-memory msbuild projects (called meta projects), and then proceeds to build the meta projects. They are very similar to traversal targets. To write these in-memory to disk, you have to set the For some reason I don't understand, sln project dependencies are implemented twice in msbuild's sln interpretation:
<CurrentSolutionConfigurationContents>
<SolutionConfiguration
xmlns="">
<ProjectConfiguration Project="{334778F6-6AC6-4BBA-AC3A-0D9AF15503EE}" AbsolutePath="D:\projects\tests\projects\CoreOnFF\Core\Core.csproj" BuildProjectInSolution="True">Debug|AnyCPU
<ProjectDependency Project="{5BDF9C4F-F6FA-4DD3-8F60-0FE79B7A77A3}" />
</ProjectConfiguration>
<ProjectConfiguration Project="{5BDF9C4F-F6FA-4DD3-8F60-0FE79B7A77A3}" AbsolutePath="D:\projects\tests\projects\CoreOnFF\FF\FF.csproj" BuildProjectInSolution="True">Debug|AnyCPU</ProjectConfiguration>
</SolutionConfiguration>
</CurrentSolutionConfigurationContents> This property is then recursively piped down to projects and gets read in Microsoft.Common.CurrentVersion.targets:AssignProjectConfiguration. Mechanism 1. seems sufficient to obtain the same behaviour as VS. Mechanism 2. is the one causing the crash in this issue because it injects the full framework project as a To turn off mechanism 2. the following property must be set to false: |
The reason this longstanding behavior breaks the build is that the sdk doesn't respect But it still seems odd to have this belt-and suspenders approach. |
…dependencies Fixes dotnet#7075 Fixes dotnet/msbuild#2274
There's a dup of this here: #2511. |
@cdmihai Consider this sln:
ProjectB and ProjectC build order is not enforced by the sln. If ProjectC is built first, it will build ProjectB because it's a ProjectReference (without going through the metaproj), but with The second workaround would be to specify a ProjectDependency even if there is a ProjectReference between the projects, but this is unmaintainable. The proper behavior would be achieved if the build tree was processed manually by getting each project's ProjectReference, correlated with custom BuildDependencies, and built with Another solution could be to add an option to skip the build when a TargetFramework is not supported instead of failing. |
I think the issues with synthetic project references have mostly been addressed and should work for single-TFM projects in VS 15.8 / 2.1.4xx CLIs. |
Hey, there is a reason for the synthetic references to exist! Thanks @JeffCyr. Repro: mixed-dependencies.zip I think the best way forward in this situation is to change the B->A link to a ProjectReference, either setting the TF for the reference explicitly <ProjectReference Include="..\ProjectA\ProjectA.csproj"
SetTargetFramework="TargetFramework=net46"
ReferenceOutputAssembly="false" /> Or adding A's TF to B's <PropertyGroup>
<AssetTargetFallback>netcoreapp2.0</AssetTargetFallback>
</PropertyGroup> Unfortunately, we can't make this behavior the default for |
@dasMulli I confirm that the issue is fixed in VS 15.9 Preview 3, thanks. |
It would be interesting to solve this problem. We were searching many days and couldn't explain what was happening. The different behaviors of dotnet build and MSBuild are really a pain point and costs of a lot of investigation time. |
Please start a new issue with details--the behavior described in this issue does not vary between |
@rainersigwald: Thanks, if have opened an issue: #10234 |
From @evildour on July 5, 2017 15:54
Steps to reproduce
Create new .NET Core class library (and solution) in VS 2017
Right click solution and add new .NET Core class library
Edit csproj file for the 2nd class library
Change its TargetFramework from netcoreapp1.1 to net45
Right click on the first class library's project and click "Build dependencies -> Project dependencies..."
Check the box to make it depend on the other class library
Rebuild in VS (everything works fine)
Open a command line and go to the sln file's directory
Run 'dotnet build'
Expected behavior
The build succeeds as it did in VS.
Actual behavior
The following error occurs:
Project '...' targets '.NETFramework,Version=v4.5'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v1.1'.
Environment data
dotnet --info
output:.NET Command Line Tools (1.0.4)
Product Information:
Version: 1.0.4
Commit SHA-1 hash: af1e668
Runtime Environment:
OS Name: Windows
OS Version: 10.0.10586
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\1.0.4
Copied from original issue: dotnet/cli#7075
The text was updated successfully, but these errors were encountered: