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

Don't publish MSBuild assemblies in the NuGet package #39

Closed
AndyGerlicher opened this Issue Mar 12, 2018 · 25 comments

Comments

Projects
None yet
4 participants
@AndyGerlicher
Member

AndyGerlicher commented Mar 12, 2018

https://developercommunity.visualstudio.com/content/problem/208668/the-finddependenciesofexternallyresolvedreferences.html

Customers are reporting issues with projects that use SimpleStubs. We added a parameter to Resolve Assembly References (RAR) in 15.6 and the common targets were updated to use the new parameter. Since Etg.SimpleStubs packages MSBuild (currently 15.5.180) it will load DLLs from that location but common targets/toolset from the installed location.

Options:

  1. Redistribute all of MSBuild. You need to define a toolset (see msbuild.exe.config) for things can be found. It would need all targets/tasks needed to do what you're trying to do. This is really hard to get right since VS installs stuff to the MSBuild extensions folder.
  2. Dynamically load MSBuild at run-time. See https://www.nuget.org/packages/Microsoft.Build.Locator/1.0.7-preview-ge60d679b53
    Code/samples available here: https://github.com/Microsoft/MSBuildLocator

If you choose one, we'll continue to have this issue where we add features and things are out of sync. I can help out with 2 if needed. If you build the repo the sample app shows a simple build and prompts which VS to use (you probably don't want to prompt, but something similar).

@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 12, 2018

The reason I package MSBuild is because Roslyn needs the MSBuild dlls to work. I am not an MSBuild expert but there should be a way to allow Roslyn to link to the MSBuild dlls in the installed location directly. However, the problem would be for users who don't have that version of MSBuild installed.

@AndyGerlicher

This comment has been minimized.

Member

AndyGerlicher commented Mar 13, 2018

Can you at minimum publish a package with MSBuild 15.6 to unblock people?

@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 13, 2018

Yes, if Roslyn can work with 15.6. I will try to upgrade as soon as I find time and give it a try.

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 21, 2018

@nehmebilal: If you use the Microsoft.Build.Locator package that @AndyGerlicher mentioned, you do not need to deploy the MSBuild assemblies to make MSBuildWorkspace function. Instead, the locator will install an assembly resolution hook that will load the MSBuild assemblies from instance of MSBuild that you register. This will make your tool more resilient to changes in VS.

@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 21, 2018

@DustinCampbell my experience with Roslyn is that if I don’t add assembly redirects to specific version of MSBuild, it usually fails. That said, I will give it a try and see what happens.

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 21, 2018

I will look at producing a small sample app for you to demonstrate if it would help.

@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 21, 2018

That would definitely help. Thanks.

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 21, 2018

Here you go!

MSBuildWorkspaceSample.zip

This is just a simple WinForms app. It does the following:

  1. Uses the Microsoft.Build.Locator package to register the default MSBuild instance on the machine.
  2. Uses MSBuildWorkspace to open solutions and projects.
  3. Dumps information to a text box.

You should be able to unzip the file, open MSBuildWorkspaceSample.sln in VS 2017, restore packages and F5. Note that it has a custom post-build step to delete the following assemblies from the output:

  • Microsoft.Build.dll
  • Microsoft.Build.Framework.dll
  • Microsoft.Build.Tasks.Core.dll
  • Microsoft.Build.Utilities.Core.dll

Let me know if you need additional help to get this up-and-running. Also, I should let you know that we are in the process of overhauling MSBuildWorkspace. This will be a major (and breaking!) update and is in PR here: dotnet/roslyn#21670.

@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 21, 2018

Thanks @DustinCampbell. I tried the tool and this is what I am seeing when I try to open a csproj:

Loading solution: C:\projects\SimpleStubs\test\TestClassLibraryTest\TestClassLibraryTest.csproj...
Loaded: 00:00:04.1057035

Errors:
[Failure] Msbuild failed when processing the file 'C:\projects\SimpleStubs\src\SimpleStubs\SimpleStubs.csproj' with message: The SDK 'Microsoft.NET.Sdk' specified could not be found.  C:\projects\SimpleStubs\src\SimpleStubs\SimpleStubs.csproj

Project: TestClassLibraryTest (8 document(s))

I tried on other projects and solutions and I see a similar message.

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 21, 2018

Could you provide the full output?

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 21, 2018

Note that the instance of MSBuild that is registered is important. If that particular MSBuild doesn't have all of the workloads installed that the project you're loading requires, MSBuild won't be able to process the project.

@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 21, 2018

MSBuild instances discovered:
1. Visual Studio Enterprise 2017 - 15.6.27428.2011

Registered: Visual Studio Enterprise 2017 - 15.6.27428.2011

Loading solution: C:\projects\SimpleStubs\test\TestClassLibraryTest\TestClassLibraryTest.csproj...
Loaded: 00:00:04.1057035

Errors:
[Failure] Msbuild failed when processing the file 'C:\projects\SimpleStubs\src\SimpleStubs\SimpleStubs.csproj' with message: The SDK 'Microsoft.NET.Sdk' specified could not be found.  C:\projects\SimpleStubs\src\SimpleStubs\SimpleStubs.csproj

Project: TestClassLibraryTest (8 document(s))

I recently updated visual studio to 15.6. I'll try to create a brand new project and test on.

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 21, 2018

Did you restore that project first? MSBuildWorkspace will not run a dotnet restore.

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 21, 2018

Also, do you have the .NET core development workload installed into VS?

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 21, 2018

MSBuild instances discovered:
1. Visual Studio Enterprise 2017 - 15.7.27517.0

Registered: Visual Studio Enterprise 2017 - 15.7.27517.0

Loading solution: D:\Projects\SimpleStubs\test\TestClassLibraryTest\TestClassLibraryTest.csproj...
Loaded: 00:00:02.4153010

No errors!

Project: TestClassLibraryTest (8 document(s))
@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 21, 2018

Ok, I will do some more investigation and get back to you. Thanks.

@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 21, 2018

@DustinCampbell Still doesn't work for me. I even tried adding the MSBuildSDKsPath as discussed here and restarted my visual studio instance.

I also verified the Visual Studio Installer and .Net Core Runtime component is installed (though I am not sure that it's reasonable to force users to have it installed to use SimpleStubs?).

Output from opening two different projects (notice the second error is different):

MSBuild instances discovered:
1. Visual Studio Enterprise 2017 - 15.6.27428.2011

Registered: Visual Studio Enterprise 2017 - 15.6.27428.2011

Loading solution: C:\projects\SimpleStubs\test\TestClassLibraryTest\TestClassLibraryTest.csproj...
Loaded: 00:00:04.9603597

Errors:
[Failure] Msbuild failed when processing the file 'C:\projects\SimpleStubs\src\SimpleStubs\SimpleStubs.csproj' with message: The imported project "C:\Program Files (x86)\MSBuild\2.0\Microsoft.Common.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  C:\Program Files\dotnet\sdk\2.1.102\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props

Project: TestClassLibraryTest (8 document(s))

Loading solution: C:\Users\nbilal\Downloads\MSBuildWorkspaceSample\MSBuildWorkspaceSample\MSBuildWorkspaceSample\MSBuildWorkspaceSample.csproj...
Loaded: 00:00:00.0440506

Errors:
[Failure] Msbuild failed when processing the file 'C:\projects\SimpleStubs\src\SimpleStubs\SimpleStubs.csproj' with message: The imported project "C:\Program Files (x86)\MSBuild\2.0\Microsoft.Common.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  C:\Program Files\dotnet\sdk\2.1.102\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props
[Failure] Msbuild failed when processing the file 'C:\Users\nbilal\Downloads\MSBuildWorkspaceSample\MSBuildWorkspaceSample\MSBuildWorkspaceSample\MSBuildWorkspaceSample.csproj' with message: The tools version "15.0" is unrecognized. Available tools versions are "14.0", "2.0", "3.5", "4.0".  C:\Users\nbilal\Downloads\MSBuildWorkspaceSample\MSBuildWorkspaceSample\MSBuildWorkspaceSample\MSBuildWorkspaceSample.csproj

Project: MSBuildWorkspaceSample (0 document(s))

C:\Program Files (x86)\MSBuild\2.0\Microsoft.Common.props does not exist on my computer.

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 21, 2018

@AndyGerlicher : Do you have any ideas based on the error messages here?

@nehmebilal : In order to use MSBuild APIs (including MSBuildWorkspace), the various MSBuild tools must be installed on the user's machine.

@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 22, 2018

@DustinCampbell in the meantime, it would be great if you can explain to me how do I figure out what version of MSBuild a particular version of Roslyn depends on? :)

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 22, 2018

You should not need to figure that out. That is actually a path of madness.

BTW: It turns out that my sample application ran into an MSBuild bug that can occur when using MSBuild APIs in an executable that has the text "msbuild" in its name. Here's a new version that should not exhibit that bug.

MSBuildWorkspaceSample - fixed.zip

@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 22, 2018

Awesome 😄

Seems to work, I'll try it in SimpleStubs soon. Thanks.

@nehmebilal

This comment has been minimized.

nehmebilal commented Mar 23, 2018

@DustinCampbell @AndyGerlicher the MSBuildLocator solution seems to work well. Thanks for your help!

NuGet is up (2.4.5). Hopefully no one will report issues 😃

@billyzkid

This comment has been minimized.

billyzkid commented Mar 23, 2018

I can confirm SimpleStubs v2.4.5 fixes the build errors we were having with VS 2017 v15.6.x

@DustinCampbell

This comment has been minimized.

Member

DustinCampbell commented Mar 23, 2018

I'm very glad to hear that!

@AndyGerlicher

This comment has been minimized.

Member

AndyGerlicher commented Mar 23, 2018

This is great, thanks @nehmebilal and @DustinCampbell !!

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