Skip to content

Major MSBuildWorkspace update#21670

Merged
DustinCampbell merged 123 commits intodotnet:masterfrom
DustinCampbell:msbuildworkspace
Apr 5, 2018
Merged

Major MSBuildWorkspace update#21670
DustinCampbell merged 123 commits intodotnet:masterfrom
DustinCampbell:msbuildworkspace

Conversation

@DustinCampbell
Copy link
Copy Markdown
Member

@DustinCampbell DustinCampbell commented Aug 22, 2017

Fixes #5557
Fixes #5668
Fixes #15102

  • Remove dependency on old COM-based host objects.
  • Add support for SDK-style projects (including multi-TFM projects).
  • Get general buy off on this source breaking change.
  • Add a Nuspec for the new Workspaces.MSBuild package.
  • Change API to account for the fact that a multi-TFM project will need to be loaded as multiple projects.
  • Add design-time batch build logic to improve performance.
  • Document how MSBuildWorkspace can be used by clients.
  • Create sample application that demonstrates how to use MSBuildWorkspace.

@DustinCampbell DustinCampbell added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Aug 22, 2017
Copy link
Copy Markdown
Member

@Pilchie Pilchie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally favorable, but:

  1. Need to figure out the breaking change story, update process, etc.
  2. Will need new new .nuspec file, publishing related stuff, etc.

Comment thread src/Samples/Samples.sln Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why these switched to Any CPU?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Samples/Samples.sln Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea what this one is?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet VS just removed it because there isn't a project GUID in the solution file matching that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, missed that this was Samples.sln, you're probably right.

@DustinCampbell
Copy link
Copy Markdown
Member Author

Will need new new .nuspec file, publishing related stuff, etc.

Yes, but I don't want to do that until this project is portable. That, unfortunately, may be a bit complicated.

@DustinCampbell
Copy link
Copy Markdown
Member Author

Need to figure out the breaking change story, update process, etc.

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?

@Pilchie
Copy link
Copy Markdown
Member

Pilchie commented Aug 22, 2017

Can/Should we use typeforwarding for the public APIs that moved?

@jaredpar @jasonmalinowski ?

@DustinCampbell
Copy link
Copy Markdown
Member Author

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.

@Pilchie
Copy link
Copy Markdown
Member

Pilchie commented Aug 22, 2017

Definitely problematic if true. I've never actually authored a type forwarder though.

@DustinCampbell
Copy link
Copy Markdown
Member Author

@Pilchie
Copy link
Copy Markdown
Member

Pilchie commented Aug 22, 2017

@DustinCampbell
Copy link
Copy Markdown
Member Author

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.

@jaredpar
Copy link
Copy Markdown
Member

@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.

@DustinCampbell
Copy link
Copy Markdown
Member Author

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?

The issue is as follows:

  • Microsoft.CodeAnalysis.Workspaces.Common contains both Workspaces and Workspaces.Desktop
  • Workspaces.MSBuild has a dependency on Workspaces
  • We want Workspaces.MSBuild to live in its own package.

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.

@DustinCampbell DustinCampbell force-pushed the msbuildworkspace branch 4 times, most recently from 9b0dea5 to 0a38f54 Compare August 28, 2017 22:22
@DustinCampbell DustinCampbell force-pushed the msbuildworkspace branch 3 times, most recently from 86835b7 to 6613bf5 Compare September 26, 2017 15:45
@DustinCampbell
Copy link
Copy Markdown
Member Author

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.

@jaredpar
Copy link
Copy Markdown
Member

jaredpar commented Oct 2, 2017

@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>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately, the plan is to make this netstandard2.0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 🍻

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 😄

Copy link
Copy Markdown
Contributor

@sharwell sharwell Oct 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 It will be a big deal for a long-standing request to provide command line automation for analyzers/fixes (on non-Windows systems).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever load this assembly in Visual Studio though?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe...

Microsoft.CodeAnalysis.Workspaces.Desktop ships in VS today. It's possible that VS extensions may have targeted it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@DustinCampbell
Copy link
Copy Markdown
Member Author

@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

Yeah, I realized that later but didn't update here. I intend to add ConditionalFacts to address this.

@maca88
Copy link
Copy Markdown
Contributor

maca88 commented Oct 29, 2017

I'm happy to say that thanks to this PR, I'm able to open and analyze projects using the MSBuildWorkspace on Linux and OSX using .NET Core. In order to make it work on .NET Core I've had to remove the BuildingInsideVisualStudio flag, otherwise it didn't worked. Another thing that I had to change are the project paths located in the solution file, as a backslash is not a directory separator on Unix e.g. ("Folder\MyProject.csproj" -> "Folder/MyProject.csproj").
Out of my curiosity, is this change planned for version 3.0.0 or a later one?

@sharwell
Copy link
Copy Markdown
Contributor

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.

We can split Microsoft.CodeAnalysis.Workspaces.Common into 3 packages:

  • Microsoft.CodeAnalysis.Workspaces
  • Microsoft.CodeAnalysis.Workspaces.Desktop
  • Microsoft.CodeAnalysis.Workspaces.MSBuild

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.)

@DustinCampbell
Copy link
Copy Markdown
Member Author

@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?

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)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DustinCampbell
Copy link
Copy Markdown
Member Author

@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.

Copy link
Copy Markdown
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

return commandLineArgs.SetItem(platformIndex, "/platform:anycpu");
}

// return AdjustPlatformCommandLineArg(commandLineArgs);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code left?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops.

<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" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DustinCampbell
Copy link
Copy Markdown
Member Author

OK. Once CI passes, I'll (finally) merge.

@DustinCampbell DustinCampbell merged commit a3f904c into dotnet:master Apr 5, 2018
@Pilchie
Copy link
Copy Markdown
Member

Pilchie commented Apr 5, 2018

🎆 💯 👍 :shipit:

@OmerRaviv
Copy link
Copy Markdown
Contributor

OmerRaviv commented Apr 5, 2018

@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 ?

@DustinCampbell
Copy link
Copy Markdown
Member Author

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.

@OmerRaviv
Copy link
Copy Markdown
Contributor

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.

@jaredpar
Copy link
Copy Markdown
Member

jaredpar commented Apr 9, 2018

@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.

@DustinCampbell
Copy link
Copy Markdown
Member Author

@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.

@DustinCampbell
Copy link
Copy Markdown
Member Author

@daveaglick: You might be interested in that as well.

@daveaglick
Copy link
Copy Markdown
Contributor

its-happening

Thanks for all your hard work getting this out the door. Looking forward to taking it for a spin.

@DustinCampbell
Copy link
Copy Markdown
Member Author

FYI that I'm also working on a sample application here: https://github.com/DustinCampbell/MSBuildWorkspaceTester.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-already-signed Concept-API This issue involves adding, removing, clarification, or modification of an API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.