Major MSBuildWorkspace update#21670
Conversation
Pilchie
left a comment
There was a problem hiding this comment.
Generally favorable, but:
- Need to figure out the breaking change story, update process, etc.
- Will need new new
.nuspecfile, publishing related stuff, etc.
There was a problem hiding this comment.
Do you know why these switched to Any CPU?
There was a problem hiding this comment.
It appears that these are the TreeTransform samples (which I did not touch). I can't imagine why these would have been x86 in the Any CPU solution configuration to begin with.
There was a problem hiding this comment.
I bet VS just removed it because there isn't a project GUID in the solution file matching that.
There was a problem hiding this comment.
Oh, missed that this was Samples.sln, you're probably right.
Yes, but I don't want to do that until this project is portable. That, unfortunately, may be a bit complicated. |
Yes, this is going to be a breaking change. I don't see a good way around that. Users will have to add a new package (Microsoft.CodeAnalysis.Workspaces.MSBuild) in order to use the new MSBuildWorkspace. It's also a binary breaking change since anyone could have been using MSBuildWorkspace inside Visual Studio, where we ship Workspaces.Desktop. However, I don't believe we intended for MSBuildWorkspace to be used within VS. Thoughts? |
|
Can/Should we use typeforwarding for the public APIs that moved? |
I think that might cause an awkward dependency. AFAIK, type-forwarding requires the old assembly to reference the new assembly. So, Workspaces.Desktop would need to reference Workspaces.MSBuild. However, that would break the NuGet packaging (if we want Workspaces.MSBuild to be in its own package) because Workspaces and Workspaces.Desktop are both included in Microsoft.CodeAnalysis.Workspaces.Common. So, Workspaces.MSBuild would need to be included in that package too. |
|
Definitely problematic if true. I've never actually authored a type forwarder though. |
|
My understanding is that was added later (in .NET 4.0) to allow types to be traced back to their original assembly so that the serializer can function with forwarded types. @jaredpar / @jasonmalinowski: please let me know if I'm wrong about that. |
|
@DustinCampbell explanation around forwarding matches my understanding. I don't really think there is a lot we can do here in terms of compat. Know this is just testing CI at the moment. But can we get a quick explanation about why we can't have Workspaces.Desktop reference Workspaces.MSBuild? That order would allow for type forwarding. But guessing there is a deliberate reason for breaking it up as said in the PR. |
The issue is as follows:
We'd like to have a packaging scheme where Microsoft.CodeAnalysis.Workspaces.MSBuild depends on Microsoft.CodeAnalysis.Workspaces.Common. However, if Workspaces.Desktop depends on Workspaces.MSBuild, we would be forced to push it into Microsoft.CodeAnalysis.Workspaces.Common instead. |
9b0dea5 to
0a38f54
Compare
86835b7 to
6613bf5
Compare
|
Hmmm... They ran on my box. It's an improvement, but I'll need to dig in to figure out way they aren't passing in CI. |
|
@DustinCampbell dont forget that we dont have VS installed on these boxes. Possible there is subtle machine state that allows it to pass on your box |
| <RootNamespace>Microsoft.CodeAnalysis</RootNamespace> | ||
| <AssemblyName>Microsoft.CodeAnalysis.Workspaces.MSBuild</AssemblyName> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
| <TargetFramework>net46</TargetFramework> |
There was a problem hiding this comment.
📝 I have a branch locally where the goal was making this netstandard1.5 (the lowest standard which the MSBuild APIs support). It was mostly complete but there was a section of important code which couldn't be purely extracted from Workspaces.Desktop using strictly type forwarding to preserve compatibility so I didn't push it forward.
There was a problem hiding this comment.
Ultimately, the plan is to make this netstandard2.0.
There was a problem hiding this comment.
Cool, that wasn't an option at the time I looked so here's to hoping netstandard2.0 has all the APIs to make it straightforward success. 🍻
There was a problem hiding this comment.
To be honest, it's not quite an option for this yet either. Moving to netstandard2.0 has implications for Visual Studio, though that might be a good thing to sort through and address now. 😄
There was a problem hiding this comment.
📝 It will be a big deal for a long-standing request to provide command line automation for analyzers/fixes (on non-Windows systems).
There was a problem hiding this comment.
Do we ever load this assembly in Visual Studio though?
There was a problem hiding this comment.
Maybe...
Microsoft.CodeAnalysis.Workspaces.Desktop ships in VS today. It's possible that VS extensions may have targeted it.
There was a problem hiding this comment.
What is the use case for this particular library? Is it only ever shipped via NuGet? That will impact our netstandard discussions.
In reply to: 156729257 [](ancestors = 156729257)
Yeah, I realized that later but didn't update here. I intend to add ConditionalFacts to address this. |
|
I'm happy to say that thanks to this PR, I'm able to open and analyze projects using the |
We can split Microsoft.CodeAnalysis.Workspaces.Common into 3 packages:
Then make Microsoft.CodeAnalysis.Workspaces.Common a metadata-only package that declares dependencies on the 3 new packages. Within the 3 new packages the dependencies are clear. Users upgrading to the new version via the metadata-only package will not be broken, nor will users who compiled against an older version. (Does not address cases where type forwarding does not apply, should any such cases exist.) |
fa4638a to
897deb5
Compare
|
@jasonmalinowski: Except for the type forwarder (which is currently blocked), I believe I've addressed your CR feedback or asked further questions. Could you take a sweep through your comments and make sure they've been addressed to your satisfaction? |
a378a48 to
1df5359
Compare
Since we're moving this type from Microsoft.CodeAnalysis.Workspaces.Desktop to Microsoft.CodeAnalysis.Workspaces, a type forward is required. There is currently a bug with the Public API analyzer with properties on forwarded types that I have to work around in the PublicAPI.Shipped.txt, but a fix is already out for that dotnet/roslyn-analyzers#1657. Once the analyzers are updated in the roslyn repo, this will get fixed.
| Microsoft.CodeAnalysis.FileTextLoader.Path.get -> string | ||
| Microsoft.CodeAnalysis.FileTextLoader (forwarded, contained in Microsoft.CodeAnalysis.Workspaces) | ||
| Microsoft.CodeAnalysis.FileTextLoader.DefaultEncoding.get -> System.Text.Encoding (forwarded, contained in Microsoft.CodeAnalysis.Workspaces) | ||
| Microsoft.CodeAnalysis.FileTextLoader.DefaultEncoding { get; } -> System.Text.Encoding (forwarded, contained in Microsoft.CodeAnalysis.Workspaces) |
There was a problem hiding this comment.
Note: This is working around a bug in the public API analyzer with properties on forwarded types. This is already fixed in the analyzer, and this file will be updated when the analyzers are updated in the Roslyn repo.
| Microsoft.CodeAnalysis.FileTextLoader.DefaultEncoding { get; } -> System.Text.Encoding (forwarded, contained in Microsoft.CodeAnalysis.Workspaces) | ||
| Microsoft.CodeAnalysis.FileTextLoader.FileTextLoader(string path, System.Text.Encoding defaultEncoding) -> void (forwarded, contained in Microsoft.CodeAnalysis.Workspaces) | ||
| Microsoft.CodeAnalysis.FileTextLoader.Path.get -> string (forwarded, contained in Microsoft.CodeAnalysis.Workspaces) | ||
| Microsoft.CodeAnalysis.FileTextLoader.Path { get; } -> string (forwarded, contained in Microsoft.CodeAnalysis.Workspaces) |
There was a problem hiding this comment.
Note: This is working around a bug in the public API analyzer with properties on forwarded types. This is already fixed in the analyzer, and this file will be updated when the analyzers are updated in the Roslyn repo.
|
@jasonmalinowski: The type forward is now in place. I believe I've addressed all of your feedback. Please let me know if that's not the case. |
| return commandLineArgs.SetItem(platformIndex, "/platform:anycpu"); | ||
| } | ||
|
|
||
| // return AdjustPlatformCommandLineArg(commandLineArgs); |
| <ProjectReference Include="..\..\Compilers\CSharp\Portable\CSharpCodeAnalysis.csproj" /> | ||
| <ProjectReference Include="..\..\Compilers\Test\Resources\Core\CompilerTestResources.csproj" /> | ||
| <ProjectReference Include="..\..\Compilers\VisualBasic\Portable\BasicCodeAnalysis.vbproj" /> | ||
| <ProjectReference Include="..\..\EditorFeatures\Core\EditorFeatures.csproj" /> |
There was a problem hiding this comment.
Any idea which project reference was added that required this to be added? BuildBoss is forcing transitivity which I get, but still seems odd our MSBuild workspace tests depends on IDE code, even through some indirect chain?
There was a problem hiding this comment.
It's because WorkspaceTestServices now references EditorFeatures. I'm not a fan of this reference. It feels like a layering violation. This is from @sharwell's recent changes for unit tests using MEF.
|
OK. Once CI passes, I'll (finally) merge. |
|
🎆 💯 👍 |
|
@DustinCampbell Congratulations and thanks for all your hard work! We'd love to start using this as soon as we can and provide feedback. However, the new Workspaces.MSBuild NuGet package does not appear to be available yet on the roslyn-master-nightly feed? Is there any publicly available way we can already consume this ? |
|
Patience @OmerRaviv. It's only just been merged and its still nighttime in the U.S. (my clock reads 3:54 am 😄). I'll follow up with folks today to see if there're any additional steps to push this package to our nightly feed. |
|
Thanks, @DustinCampbell! Will try my best to be patient 😄 I still don't see it on the roslyn-master-nightly MyGet stream, so I assume there's some additional steps needed? Happy to send a PR if this is something an outsider can fix. |
|
@OmerRaviv no additional steps are needed here, at least in the GitHub repository. Looks like there is an issue with how our official builds are running at the moment. I'm following up. |
|
@OmerRaviv: The package is now available from the roslyn feed: https://dotnet.myget.org/feed/roslyn/package/nuget/Microsoft.CodeAnalysis.Workspaces.MSBuild. Here is the first draft of a document I'm working to describe how to use MSBuildWorkspace: https://gist.github.com/DustinCampbell/32cd69d04ea1c08a16ae5c4cd21dd3a3. |
|
@daveaglick: You might be interested in that as well. |
|
FYI that I'm also working on a sample application here: https://github.com/DustinCampbell/MSBuildWorkspaceTester. |

Fixes #5557
Fixes #5668
Fixes #15102