繁体   English   中英

在Visual Studio命令提示符2010中构建c#dll时如何指定.net目标框架?

[英]How to specify .net target framework when building c# dll in Visual Studio Command Prompt 2010?

我不是很熟悉构建dll,也不熟悉Visual Studio。 但我在Unity3d中有几个文件,我总是使用Visual Studio Command Prompt 2010构建一个DLL。这似乎工作正常,除了构建到.net目标框架4,它需要3.5才能与Unity一起工作。 但是,我找不到命令行参数来指定它。

那么,这是我的问题,如何在命令提示符中指定它? (如果可能的话)

您应该能够进入项目属性(右键单击解决方案中项目名称上的+属性)并在那里指定目标框架。

TargetFramework只能在Project文件中配置,不能作为切换器传递给CSC.exe,请参阅下面示例中的TargetFrameworkVersion和TargetFrameworkProfile的设置。

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

使用MSBuild.exe:

msbuild.exe MyProj.proj /p:TargetFrameworkVersion=v2.0;Configuration=Release /tv:3.5

因此覆盖proj文件以及ToolsVersion中的值。

要找出使用哪个msbuild版本的默认值,请启动Visual Studio命令提示符(可在“开始”菜单>“Microsoft Visual Studio 2010”>“Visual Studio工具”中找到)并键入msbuild。 输出的第一行将保存您的BuidEngineversion:

Microsoft (R) Build Engine Version 4.0.30319.1

来自msdn doc:

MSBuild uses a tool set of tasks, targets, and tools to build an application. Typically, a MSBuild tool set includes a microsoft.common.tasks file, a microsoft.common.targets file, and compilers such as csc.exe and vbc.exe. Most tool sets can be used to compile applications to more than one version of the .NET Framework and more than one system platform

您可以检查环境变量以查找所安装框架的版本:从Visual Studio命令提示符设置F给出了以下结果:

Framework35Version=v3.5
FrameworkDir=c:\Windows\Microsoft.NET\Framework\
FrameworkDIR32=c:\Windows\Microsoft.NET\Framework\
FrameworkVersion=v4.0.30319
FrameworkVersion32=v4.0.30319

ToolSet说明ToolSetVersion

暂无
暂无

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

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