My question is simple: How can I do multi-targeting in command line compiler (csc.exe), especially to .Net 4 Client Profile?
edit: Ok, Is my que
If you need to compile at runtime, then you should consider the providers in System.CodeDOM, which allow compilation without invoking a separate process.
To answer your original question, if you turn the MSBuild verbosity to Detailed in Visual Studio (Options - Projects and Solutions - Build and Run) and build a project targeted at client profile, you will see this in the build output:
Csc.exe (stuff...) Program.cs Properties\AssemblyInfo.cs "C:\...\Temp\.NETFramework,Version=v4.0,Profile=Client.AssemblyAttributes.cs"
The path in quotes is actually a generated temp file, containing:
[assembly: TargetFrameworkAttribute(".NETFramework,Version=v4.0,Profile=Client", FrameworkDisplayName = ".NET Framework 4 Client Profile")]
So, you should be able to use that attribute in your own code if you are invoking csc directly.
TargetFramework can be configured in the Project file only and can't be passed as a switch to CSC.exe, see settings for TargetFrameworkVersion and TargetFrameworkProfile in below example
So the only way to dynamically set is to modify the project file with below setting and compile with csc.exe if you want to set Client Profile
Targetting .NET Framework 4.0 Client Profile
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A5F58561-47CA-482A-83E0-1D43C312B0A7}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ConsoleApplication1</RootNamespace>
<AssemblyName>ConsoleApplication1</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
Targetting .NET Framework 4.0
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A5F58561-47CA-482A-83E0-1D43C312B0A7}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ConsoleApplication1</RootNamespace>
<AssemblyName>ConsoleApplication1</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile></TargetFrameworkProfile>
</PropertyGroup>