简体   繁体   English

命令行编译器(csc.exe)中的多目标

[英]multi targeting in command line compiler (csc.exe)

My question is simple: How can I do multi-targeting in command line compiler (csc.exe), especially to .Net 4 Client Profile ? 我的问题很简单:如何在命令行编译器(csc.exe)中进行多目标定位,尤其是对.Net 4 Client Profile


edit: Ok, Is my question too simple? 编辑:好的,我的问题太简单了吗?

The compiler, targeting to .net 4.5, is %windir%\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe . 面向.net 4.5的编译器为%windir%\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe When I run csc source.cs , the output is targeting to .net 4.5. 当我运行csc source.cs ,输出的目标是.net 4.5。

I want to target to .net 4 client profile in command line compiler(csc.exe), such as csc /targetFramework="v4.0;Profile=Client" source.cs . 我想在命令行编译器(csc.exe)中定位到.net 4客户端配置文件,例如csc /targetFramework="v4.0;Profile=Client" source.cs (Of course, there's no option /targetFramework ...) (当然,没有选项/targetFramework ...)

If you need to compile at runtime, then you should consider the providers in System.CodeDOM , which allow compilation without invoking a separate process. 如果需要在运行时进行编译,则应考虑System.CodeDOM中提供程序 ,这些提供程序允许在不调用单独进程的情况下进行编译。

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: 要回答您的原始问题,如果在Visual Studio中将MSBuild的详细程度设置为“详细”(“选项”-“项目和解决方案”-“构建和运行”),并针对客户配置文件构建项目,则将在生成输出中看到以下内容:

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. 因此,如果直接调用csc,则应该能够在自己的代码中使用该属性。

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 只能在项目文件中配置TargetFramework,并且不能将其作为CSC.exe的开关传递,请参见以下示例中TargetFrameworkVersionTargetFrameworkProfile的设置

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 因此,动态设置的唯一方法是使用以下设置修改项目文件,然后如果要设置客户端配置文件,则使用csc.exe进行编译

Targetting .NET Framework 4.0 Client Profile 定位.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>Client</TargetFrameworkProfile>
  </PropertyGroup>

Targetting .NET Framework 4.0 定位.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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM