0

I want to set up a complete C# Project in Code and specify the TargetFrameworkVersion property of it.

The reason behind is, that we wrapped the Roslyn APIs to compile our generated code, but although specifying the LanguageVersion in the CSharpParseOptions and using the ToolLocationHelper to find the Net47 reference assemblies, our output is a .Net Framework 4 DLL, instead of a desired .Net Framework 4.7.

So we tried to build a C# Project around our generated source code, where usually the TargetFrameworkVersion would be specified. This also seemed to be a more stable solution, than just adding the bare reference assemblies to the compilation.

So far I found the ProjectInfo object, which is contained in the Microsoft.CodeAnalysis namespace. However this doesn't seem to allow additional project properties, nor does it have a property or option where you can specify the target framework.

Can someone point me to the right direction on how to set the TargetFrameworkVersion in code? How does the Roslyn Compiler find out its .NET 4?

Sascha
  • 3
  • 3
  • Can you show how you build the project? CodeAnalysis isn't the correct namespace as far as I know, you need this: https://stackoverflow.com/questions/7264682/running-msbuild-programmatically – stijn Dec 09 '21 at 08:09

0 Answers0