简体   繁体   中英

compile by csc.exe without VS and .NET Framework SDK

I have 2 windows machines: Machine1 has Visual Studio 2010; Machine2 has only .NET Framework 4.0 Client Profile without any Visual Studio or .NET Framework SDK.

Compiling one simple C# test (test.cs includes "using System.Data;"):

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /target:exe test.cs

It works fine on Machine1. But failed on Machine2 with:

test.cs(2,14): error CS0234: The type or namespace name 'Data' does not exist in
        the namespace 'System' (are you missing an assembly reference?)

I copied the "C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\System.Data.dll" to the current directory but it still failed.

Added "/r:system.data.dll" when compiling will work:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /r:system.data.dll /target:exe test.cs

Do you know the reason?

The compiler will attempt to automatically load a file named csc.rsp , a file that contains default compile options. Unless you compile with the /noconfig option. That file contains a bunch of /reference options for common .NET Framework assemblies, System.Data.dll is one of them.

There is a csc.rsp file on all my machines, it is located for example in C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319 on the one I'm using now.

So very high odds that you are using a machine that doesn't have that file. I don't know if that's specific to the Client profile, I've always avoided it. But a quick check with Windows Explorer will give you a hint.

The .NET Client Profile is a cut-down version of .NET intended for client (user interface) applications. Not all of the assemblies and classes provided in the full .NET exist in the Client Profile. If you wish to write and application that works on both, you will have to restrict yourself to just those classes and assemblies that exist in the Client Profile (as it is a subset).

You may find it more convenient to simply install the full .NET on machine 2.

Notice also that, as of .NET 4.5, the Client Profile no longer exists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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