-
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
Access AllEvaluatedItems
(not just ordered with respect to items of the same item type) from within .csproj
#4460
Comments
No, that's not possible. As a rule, MSBuild doesn't make it possible to observe project state from inside a project; rather it requires explicit reference to the items or properties you are referencing. This makes it easier to reason about what a given snippet of code will do. May I ask what you're doing that led you to ask about this? |
That's a shame. It would be nice if MSBuild exposed a way to enumerate all project items in the order that they are declared (irrespective of item type). What I would like to be able to do is declare some <ItemGroup>
<PackageReference Include="somePackage">
<ProjectReference Include="someProject">
<PackageReference Include="someOtherPackage">
<ProjectReference Include="someOtherProject">
</ItemGroup>
<!-- or even... -->
<ItemGroup>
<PackageReference Include="somePackage">
</ItemGroup>
<ItemGroup>
<ProjectReference Include="someProject">
</ItemGroup>
<ItemGroup>
<PackageReference Include="someOtherPackage">
</ItemGroup>
<ItemGroup>
<ProjectReference Include="someOtherProject">
</ItemGroup>
<!-- and then... -->
<Task Name="WriteOrderedRefsToFile" BeforeTargets="BeforeBuild">
<!-- write the ordered references to a file for lookup at runtime -->
</Task> Essentially I would like the order that a project's dependencies are declared in to be meaningful (regardless of whether they are project or package references), and at runtime I can use this order to affect the execution order of 'jobs' exposed by those dependencies. Can you think of a way to achieve this? At the moment I'm stuck doing something like this (unless of course I want to depend on a custom VS extension).
↑ this approach isn't very convenient/maintainable as new references are added or when reordering is required :( |
And why do you need to implement such approach? What are you trying to achieve with that. I believe the manual approach is the only thing that I can think of. Though, in my opinion, neither of them would be particularly maintainable. |
There are three reasons I can think of;
All in all, this means that the behaviour of the 'chain of responsibilities' is apparent simply by peeking at the composing project in the solution explorer, and that is also where the developer performs the reordering, at the click of a button / tap of the keyboard ↑ ↓. It's also naturally where the developer can add and remove handlers, and pull them into other composing projects. Note: |
Feature Enquiry
Is it possible from inside a .csproj file (perhaps using a custom MSBuild task) to access an ordered list of project items that are not just ordered with respect to the same item type? So, in the example below, being able to determine that one dog comes before the cat and another one comes after it.
I'm aware that this property appears to provide this behaviour, but I only know how to access this from a VS extension project, not from inside MSBuild. Is this possible?
The text was updated successfully, but these errors were encountered: