-
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
Merging of multiple Directory.Build.props #2456
Comments
It finds the innermost one and stops. However, it's possible to manually opt into continuing: just add <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props'))" /> to your "innermost" |
@rainersigwald Thank you for that! Does it "stop" after it merges into the solution-level file, or will it continue till it gets to I ask because I'm not sure I understand your "off switch" comment, and I've looked at the source but I don't really understand how msbuild works behind the scenes... |
It stops at the first For "off switch" what I meant is that the common targets allow two customization points for d.b.props:
You don't need either of those to continue the search, because you already know that you're actively importing |
Okay so for anyone else like me who is a msbuild amateur, I summarize all your explanations thus:
...or more simply: the first |
An excellent summary! Would you like to open a PR for the docs with that information? |
Turns out that
doesn't work - I get an error that the import causes a circular dependency. However when I hardcode it then it works:
I think it has something to do with the starting directory, which doesn't correspond to what I would assume. If the csproj file automatically imports the dbprops above it (the "inner" file), which in turn imports the dbprops above it (the "outer" file), then the import command essentially points to the inner file, i.e. itself, which causes the circular dependency. So I tried this:
But that doesn't help. UPDATE:
I've created a new PR for that. |
Ah so this is where this was coming from 😀 |
@dasMulli Yep I put a link in the SO question to this issue, was sure you saw it... I thought I'd get a quick resolution, and I did 😉 Thanks again BTW. The PR has your proposed change. |
@rainersigwald that sounds like a bug. GetPathOfFileAbove should not attempt to load itself again. I'm also hitting this in corefx. |
@ViktorHofer unfortunately, this would be a breaking change. While unfortunate for nested msbuild files, the current behavior semantically aligns with most other behaviors of MSBuild - all relative paths start at the project direcotry, project directory is the CWD for all code being executed by default etc. So |
I'm not proposing to change the default directory GetPathOfFileAbove starts to search from. What I tried to say is that GetPathOfFileAbove should not return the path of the calling script as that doesn't make any sense. |
Depends on how you look at it.. if you see it from the context of the project file, it's okay.
I think it would be weird for a "find me a file in the project directory hierarchy named X" function to have a special case ".. but not if it the path is the same as the currently executing msbuild file". Seems like a hardcoded workaround for the combination of the 3 conditions listed above. Personally, i'd prefer an additional property on |
I agree with @dasMulli, except for this part:
I don't think it'd help here, because it wouldn't follow the user intent ("recurse upward")--it'd just silently end the search. Another possible improvement would be to put this logic directly in Import; something like <Import Project="Directory.Build.props" Search="Above" /> (undoubtedly better wording is possible). Then the case of "continue D.B.props search" would be really concisely expressed. But I'm not sure it's worth the additional complexity. |
true! for some usages one could also use a function that returns an ordered list of project files in the tree and make use of the list import that was introduced during 15.*. But that would remove the option to explicitly block traversal. |
Okay, let me summarize my ask. What I'm missing is a functionality to import a file - with the same name as the calling script - somewhere in the directory structure above. A search attribute on the import element itself would be very convenient. |
I don't get the syntax of GetPathOfFileAbove
So where does this second parameter come from? |
@rainersigwald one way to enable @ViktorHofer 's scenario could be to special case Right now that's failing the build, so this would not be a breaking change. It would be taking syntax that right now has no valid meaning, and making it useful. It would allow us and others using thoughts? It's a bit of a shame this doesn't work since it was explicitly the use case I described in my original proposal for |
I'm trying to understand whether how/if this file is merged with others in the solution tree, and at what point in the build process.
From the guide it's not clear to me whether merging occurs? The section "Search scope" explains that it "stops" once it finds the file. However I'm under the impression that my file is merged with the default stuff for msbuild, so some kind of merging does occur.
Suppose I have this
Then for any given project, does msbuild
If it doesn't merge like I've described, is it possible to do somehow?
The text was updated successfully, but these errors were encountered: