Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
针对较旧的.NET framework编译一个单独的C#文件_C#_.net_Windows_Csc - Fatal编程技术网

针对较旧的.NET framework编译一个单独的C#文件

针对较旧的.NET framework编译一个单独的C#文件,c#,.net,windows,csc,C#,.net,Windows,Csc,我有一个简短的C#脚本,它使用了各种语言和不同的.NET库的各种功能: using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Net; using System.Reflection; using System.Runtime.InteropServices; using System.

我有一个简短的C#脚本,它使用了各种语言和不同的.NET库的各种功能:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Text;
using System.Threading;
using Microsoft.Win32.SafeHandles;
可以找到完整的脚本

我使用以下命令编译它:

%WINDIR%\Microsoft.NET\Framework\v3.5\csc.exe code.cs /debug /nologo
但事实证明,默认情况下,.NETFrameworkV3.5在某些Windows发行版上不可用

编译此代码的最佳方法是什么,这样它就可以在Windows Vista、7、8、8.1和Server 2008上运行,而无需下载和安装.NET framework

我试着找

%WINDIR%\Microsoft.NET\Framework\v3.0\csc.exe

二进制,但它在我的机器上不存在。

据我所知,没有针对.NET 3的编译器,因为它只是带有一些额外程序集的.NET 2。因此,除了tjere之外,不需要另一个编译器:.NET编译器

因此,您应该能够使用该编译器编译项目,该编译器位于
WINDIR%\Microsoft.NET\Framework\v2.0.50727\csc.exe


只要您的代码不使用.NET4特定的功能,这将起作用。然后,您需要使用该编译器,并在每个尚未安装该版本的系统上安装.NET客户端

app.config
文件中,您需要指定希望应用程序支持的。因此,如果您想支持3.0或更高版本,您需要

<configuration>
   <startup>
      <supportedRuntime version="v2.0.50727"/>
      <supportedRuntime version="v4.0"/>
   </startup>
</configuration>

您还需要确保项目设置中仅以.NET 3.0为目标,因为该版本与Windows Vista捆绑在一起


如果在“添加/删除程序”中禁用了.NET,您将无能为力,您需要让用户自行安装某些版本,或将其作为部署的一部分进行安装(安装安装程序或单击即可)。

问题不在于您需要转到旧的框架,问题是,新的东西只能在新的框架上工作。因此,您需要
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\csc.exe
@ScottChamberlain,但是.NET没有附带到Windows Vista,例如,默认情况下?它在“添加-删除程序”中。但是它可能被启用,也可能未被启用,如果没有设置,您的程序对此无能为力。exe您需要在.proj文件中将
TargetFramework
属性设置为所需的版本。查看在哪里创建app.config文件?我如何让“csc.exe”可执行文件意识到它?您将app.config文件放在任何需要的地方,使用标志告诉csc:
csc.exe code.cs/debug/nologo/appconfig:app.config
谢谢!作为一个不经常使用.NET的人,我自己用谷歌搜索所有信息并不容易。非常感谢你的回答。我试试这个。.NET2.0是大多数Windows版本的共同特征吗?.NET2编译器最多只能编译3.5版本的代码。如果只使用最大值为3.5的引用,则没有问题。