Giter Club home page Giter Club logo

Comments (25)

billyzkid avatar billyzkid commented on May 18, 2024 4

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

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024 3

@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 πŸ˜ƒ

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024

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.

from simplestubs.

AndyGerlicher avatar AndyGerlicher commented on May 18, 2024

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

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024

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

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024

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

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024

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

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024

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

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024

That would definitely help. Thanks.

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024

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.

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024

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.

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024

Could you provide the full output?

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024

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.

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024
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.

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024

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

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024

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

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024
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))

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024

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

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024

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

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024

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

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024

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

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024

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

from simplestubs.

nehmebilal avatar nehmebilal commented on May 18, 2024

Awesome πŸ˜„

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

from simplestubs.

DustinCampbell avatar DustinCampbell commented on May 18, 2024

I'm very glad to hear that!

from simplestubs.

AndyGerlicher avatar AndyGerlicher commented on May 18, 2024

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

from simplestubs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.