2014-02-19 51 views
1

我的問題很簡單:如何在命令行編譯器(csc.exe)中執行多重定位,特別是.Net 4 客戶端配置文件在命令行編譯器(csc.exe)中的多重定位


編輯:好的,我的問題太簡單了嗎?

定位到.net 4.5的編譯器是%windir%\Microsoft.NET\Framework\v4.0.30319\csc.exe。當我運行csc source.cs時,輸出將定位到.net 4.5。

我想在命令行編譯器(csc.exe)中使用.net 4客戶端配置文件,例如csc /targetFramework="v4.0;Profile=Client" source.cs。 (當然,沒有選項/targetFramework ...)

+1

你能更具體嗎? –

+0

@JohnSaunders請參閱編輯 – ikh

+0

你能否正確配置你的.csproj並使用msbuild? –

回答

4

如果您需要在運行時編譯,那麼你應該考慮providers in System.CodeDOM,這讓編譯而不調用一個單獨的進程。

要回答你原來的問題,如果你在Visual Studio中打開詳細的MSBuild詳細信息(選項 - 項目和解決方案 - 構建和運行)並構建一個針對客戶端配置文件的項目,你將在構建輸出中看到:

​​

引號中的路徑實際上是一個生成的臨時文件,其中包含:

[assembly: TargetFrameworkAttribute(".NETFramework,Version=v4.0,Profile=Client", FrameworkDisplayName = ".NET Framework 4 Client Profile")]

所以,你應該能夠使用日如果您直接調用csc,則在您自己的代碼中使用屬性。

+0

我說,「編譯在運行時」,就是比如'的Process.Start(「CSC」)'..反正,謝謝! – ikh

2

TargetFramework只能在項目文件中進行配置,並不能作爲一個開關CSC.EXE過去了,看到設置TargetFrameworkVersionTargetFrameworkProfile在下面的例子

所以要動態設置的唯一方法是修改項目文件與下面的設置,如果你想設置客戶端配置文件與CSC.EXE編譯

靶向.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> 

靶向的.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>