-
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
Project-to-project reference fails to detect correct multi-target framework if <TargetFramework> is defined #7856
Comments
Yes, and that's the expected behavior! Do you need to specify singular |
My company's build infrastructure specifies a default To me, it seems even if |
When you build the project But when using project reference, the resolution logic thinks it's a single target build because In the meantime, the specific problem with your setup considering the current project reference behavior is that you're trying to reference <ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" SetTargetFramework="TargetFramework=$(TargetFramework)" /> |
Thanks for the tip! While it works, the disadvantage is every new project reference made to ClassLibrary1 will need this special workaround. It doesn't "just work". I am currently manually unsetting the target framework in my ClassLibrary1 csproj file by doing this: <TargetFramework></TargetFramework>
<TargetFrameworks>net6.0;net6.0-windows</TargetFramework> This allows other projects to reference ClassLibrary1 normally. However, unsetting the target framework is also not ideal, since every project in our solution that wants to multi-target now needs to know to manually unset the target framework.
In addition to the build preferring It just seems to be that if both Hopefully changing the project reference behavior can be considered! |
IMO, The precedence of
I get it but understand that if From what I understand, the role of the |
That's a good point! I did not think about that. One potential problem I can currently think of is if any project decides to override the default target framework with a different, single, I think a lot of these problems could be avoided if |
I think they left |
Project files should specify only
Unsetting via
There is also a performance implication: the "outer" build triggered when there are only We spent some time in team triage today trying to think of a way to warn or message the "TF xor TFs" requirement but didn't come up with anything that sounded particularly great. |
@dsplaisted I think the SDK team should come up with something, be it a warning or |
@rainersigwald a simple verification of unnecessary single TF value in TFs property could be: <Target Name="ValidateTargetFrameworks" AfterTargets="_ComputeTargetFrameworkItems" Condition=" '$(TargetFrameworks)' != '' ">
<Warning Condition="'@(_TargetFramework->Count())' <= 1"
File="$(MSBuildProjectFile)"
Text="<TargetFrameworks> property requires multiple frameworks. For a single value use <TargetFramework>" />
<Warning Condition="'@(_TargetFramework->Count())' != '@(_TargetFrameworkNormalized->Count())' "
File="$(MSBuildProjectFile)"
Text="Remove duplicates from <TargetFrameworks>" />
</Target> Do you think it could be shipped as a MSBuild change wave feature? |
That sounds like a breaking change (adding a warning) for a legal situation (doing a "foreach" with one item isn't ideal but doesn't cause very many problems). I would expect a very high bar for such a thing. (Adding it as a BuildCheck/analyzer would make sense to me.) |
In one C# project, I deliberately set |
Pinning your comment to #1777 :) |
Then the tooling should enforce this, not act in a completely illogical way of silently ignoring If implementing the aforementioned logical behaviour is a breaking change, then add a flag we can set in |
If a project has both
<TargetFramework>
and<TargetFrameworks>
defined, other projects cannot correctly reference the project's target framework that is different than what<TargetFramework>
specifies.Building the project with both properties defined does correctly produce the binaries for each targeted framework. It's just project-to-project references that doesn't work.
Create project A (ClassLibrary1) like so:
and project B (ClassLibrary2) like so:
Project B (ClassLibrary2) will fail to build with the following error:
From the binlog, it seems MSBuild will treat project A as having a single target framework:
If I remove
<TargetFramework>
in project A, then MSBuild correctly treats project A as having multiple target frameworks:The text was updated successfully, but these errors were encountered: