-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
MSBuildWorkspace.OpenProjectAsync throws InvalidOperationException when invoked from custom MsBuild task #14206
Comments
Oh, and expanding on this:
Doesn't have to be VS. I'm using just |
I get the same exception when I run your code from a console application which references |
I ran into similar problems in Scripty. It's actually an MSBuild limitation - you can't run one build from within another. @AArnott has a definitive explanation here: #4974 (comment) I worked around it by launching a separate process from inside the task to perform the Roslyn work that creates a workspace: https://github.com/daveaglick/Scripty/blob/f02ce93c7b3c7a75885497290e6310720b88568f/src/Scripty.MsBuild/ScriptyTask.cs#L67 |
@daveaglick
@svick Really appreciate the feedback. Thanks. |
@per-samuelsson: What ultimate thing are you trying to build here? We've generally been of the opinion (as you've noted) to "not do that", since there's a lot of challenges and might be other hookups available. |
We are trying to get Starcounter to level-up to .NET Core. As part of that, we need to continue support our development model that has always been based on something we usually refer to as weaving. In previous versions, we've always done this on IL (binary) level, transforming .NET assemblies on the fly. With the launch of Roslyn ("compiler as a service") a few years ago, it was kind of like Christmas for us (rationale: IL-weaving is not very funny). However, we've got somewhat disappointed over time. From our perspective, what has happened is that yes, Roslyn has made compiling go from a black-box to something you can enjoy the services of. But at the same time, no, it's still a black-box in the sense that .NET Core does not support any way to really get involved in compiling of user code. There is just no way to hook into that. As I wrote in #10882 a couple of months ago, we got pretty bruised by you guys dropping the support for Then it seemed source generators would be the thing that kind of would enable a (more restricted) similar experience, and we started tracking that and prototyping on it (again, see #10882). However, then at some point it was no longer part of C# 7.0 and now like several times per week, I try to see if there is some activity on that, but the track seems just dead and nothing new happens (i.e. no new issue activity on Original/Replace since like July and no new commits in that feature branch either). With our customers increasingly interested in .NET Core and we want to support more platforms, we've found ourselves in a position where we just can't wait any more. Hence, we are trying to be as broad and open as possible, trying to find ways to realize this thing, and one of those is turning to some MsBuild + Roslyn workspaces solution. It's also somewhat a result of your planning to drop project.json, turning to MsBuild, which also is a bit hard to cope with when you try to retarget a product such as ours to .NET Core. |
@mattwar can you comment on this, having looked into both generators and msbuildworkspace the most? |
@per-samuelsson instead of using MsbuildWorkspace you can use CommandLineProject with AdHocWorkspace. You'll have to pass all the same arguments into your target that the csc target has and convert them to command line arguments. The result will be the same as if you used MsbuildWorkspace but without using msbuild recursively. |
Thanks for the feedback and the hints. I'll review and try that approach eventually for sure. |
Short follow-up: what about getting those workspace bits running x-plat, will/should it work? Reason I'm asking is I'm getting some weird restore problems on RC3 when bringing anything but standard CodeAnalysis in. Could o/c very well be on my part though, not skilled enough setting that up properly. |
Hm, looks like I've been bit by #16040. I'll see if I can understand a way to work around it. |
I was able to restore by using the workaround suggested in the OP of referenced issue, but still seem unable to access I now studied its code, and also noticed that when restored, the only home of I guess that mean no x-plat for |
Yes, that means CommandLineProject is not x-plat. I suspect there is no longer any reason why it couldn't be. A lot of the code in this desktop project no longer needs to be there. |
Ouch. Then that path is unfortunately dead for us, as our main objective going .NET Core is being able to offer our product on more platforms. To bad, because I was really getting increasingly exited with the solution you proposed. Thanks for the feedback. |
Since we are yet again in a position where we need to find a way going forward on our .NET Core path, can I just ask another thing regarding:
That would mean that at this point, using Roslyn workspaces (including So, if those things are in fact Windows-specific, is there any place I could vote for it to be a prio to address that (given you hinted they might not even had to be any more)? |
I expect it's something that we will do at some point, but I'm not exactly sure how that will shake out yet, since both use some Windows specific code (like |
Thanks @Pilchie. That certainly get me one step further.
If I still would want to give |
Aha, found out my self by thinking a little (and being lucky): it's about the target framework of course. Those Then again, thanks, and I have no more questions at this point. |
I havent found anywhere you wouldn't support this scenario, and even though its a bit on the exotic side, I'll report it in case you want to dig into it.
Steps to Reproduce:
Execute()
, add the code below.In
Task.Execute()
Expected Behavior:
A new
Project
instance.Actual Behavior:
An (aggregated)
InvalidOperationException
:More:
If I do the same in a separate process / standard application, it works like a charm.
The text was updated successfully, but these errors were encountered: