-
Notifications
You must be signed in to change notification settings - Fork 693
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
set ExcludeRestorePackageImports to true for inner build targets in pack #1653
Conversation
This seems overly broad in its goal. What if the whole point of the package you're referencing is to affect the contents of the resulting nupkg? That, for example, is the whole point of Nerdbank.MSBuildExtension which dramatically manipulates the contents of a package. |
@@ -256,7 +256,8 @@ Copyright (c) .NET Foundation. All rights reserved. | |||
Condition="'$(IncludeBuildOutput)' == 'true'" | |||
Projects="$(MSBuildProjectFullPath)" | |||
Targets="_GetBuildOutputFilesWithTfm" | |||
Properties="TargetFramework=%(_TargetFrameworks.Identity);"> | |||
Properties="TargetFramework=%(_TargetFrameworks.Identity); | |||
ExcludeRestorePackageImports=true;"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding global properties to an MSBuild task invocation like this will cause MSBuild to re-build the transitive closure of targets for the target(s) you're asking to build. If _GetBuildOutputFilesWithTfm
depends on other targets (or other targets have BeforeTargets
or AfterTargets
set on this one) I'm concerned that you'll end up double-building them as a result of this. And as MSBuild targets often have non-idempotent side effects and dramatic impact on build perf, we should strive to keep the global properties the same everywhere we can.
Was the set of global properties you had before this change identical to those used for inner-build invocations from the dotnet SDK targets?
@AArnott can you provide more context on what is it that Nerdbank.MSBuildExtension does? The only impact this change will be on files that go into lib folder , source files and pdbs (for symbol packages) and framework assembly references - those things a PackageReference won't be able to change. |
If I were to implement an msbuild task distributed via NuGet that creates content files to be packaged as |
Note that |
@dasMulli with the change i have in place, the scenario you described would still work as is. However, i am still debating whether it's acceptable to do so or not. For Grpc.Core either the package author should update the package and set Pack to false on each of those Content items, or the consumer of the package should add Exclude="Build" on the PackageReference declaration. The consumer could even set "ExcludeRestorePackageImports=true" in their csproj to get rid of the targets from PackageReferences. The question here is what is the right default? |
cc @jskeet fyi |
@dasMulli @AArnott I also don't get why a PackageReference (say A.nupkg) wants to include Content in the referencing project (say B). Given that dotnet restore is transitive, A.nupkg will be a part of the restore graph, and if it's authored correctly, it can use contentFiles to add the content to the consuming project. |
@rohit21agrawal said:
PackageReferences can change what goes into the lib folder. They can basically do anything they want to via their imported .targets file. And Nerdbank.MSBuildExtension in particular does just that: it redirects all outputs from the lib folder to another folder (tools or build) in the package, and adds more files as well.
My scenario isn't adding "Content". But it does dramatically impact other elements of the package that references Nerdbank.MSBuildExtension. And all referencing projects should set |
i am closing this PR for now as we need to revise the scenario and come up with a better solution that fits the needs of the community. |
Fixes: NuGet/Home#3927
Also fixes NuGet/Home#5281
This makes sure that the targets from PackageReferences don't affect the contents of the resulting nupkg.