Skip to content
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

Is there any way to call or invoke MSBuildLocator in the net4x from a dotnet SDK project? #291

Closed
awesome-liuxiao opened this issue Apr 29, 2024 · 4 comments

Comments

@awesome-liuxiao
Copy link

I've noticed that this article tells that it is impossible to directly call a .net framework msbuild in a .net sdk project; but I'm wondering that is it possible to invoke .net framework msbuild as an assembly and use its methods (such as RegisterMSBuildPath() or RegisterInstance()) to build a .net framework based project and collect the compilation result?

@YuliiaKovalova
Copy link
Contributor

Hi @awesome-liuxiao,

MSBuildLocator running on .NET Core does not support invoking MSBuild assemblies targeting the .NET Framework. However, you can still build a project with a TargetFramework set to net472 or a similar version using the .NET Core SDK.

If you need further clarification or have specific requirements, please feel free to ask. Providing additional details will help us address your needs more accurately.

@awesome-liuxiao
Copy link
Author

hi @YuliiaKovalova ,

Thank you for your reply,
I understand that it is difficult to invoke different msbuild assemblies between .net sdk and .net framework projects; therefore, I've changed my strategy to build two independent projects for .net sdk and .net framework, respectively. But now when I trying to load assembly called Microsoft.CodeAnalysis.CSharp.CodeStyle for the two projects, the .net framework project keeps failing on getting DefinedTypes with reflectiontypeloadexception. The version of the assembly is 4.9.2, which needs dependencies of .NETStandard 2.0, and my project is targetting .net framework 4.8, which should be supported according to https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0#net-platforms-support?WT.mc_id=DT-MVP-5002999
Am I doing incorrectly?
By the way, the other project based on .net sdk loads the mentioned assembly perfectly.

@YuliiaKovalova
Copy link
Contributor

@awesome-liuxiao, can you share the full exception, including the callstack?

@awesome-liuxiao
Copy link
Author

@YuliiaKovalova
sorry to bother you, turns out I didn't import the dll as a reference in my project; after importing the dll and modified the app.config, the dll can be successfully loaded.

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants