473,651 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Command line compile with csc

When I build my winforms exe using the IDE I have a
perfectly functioning exe. If I try to build the same
project using the .Net Framework csc compiler I get a
seemingly valid exe produced (although it's only 44 Kb
instead of 76 Kb).

When I then run the csc-compiled exe I immediately get
a "System.TypeIni tializationExce ption".

What am I missing? I'm guessing there may be some batch
file that sets an environment for csc but my installation
of the Framework (v1.1.4322) contains no batch or command
files of any description. I need to get this compiling
in an environment without the full SDK or VS.Net - only
the .Net Framework will be available in the target
environment (should be enough...).

I'd appreciate replies copied to andrew dot warren at
mincom dot com.

Thanks.
Nov 15 '05 #1
11 3218
Andrew Warren <an*******@disc ussions.microso ft.com> wrote:
When I build my winforms exe using the IDE I have a
perfectly functioning exe. If I try to build the same
project using the .Net Framework csc compiler I get a
seemingly valid exe produced (although it's only 44 Kb
instead of 76 Kb).

When I then run the csc-compiled exe I immediately get
a "System.TypeIni tializationExce ption".

What am I missing? I'm guessing there may be some batch
file that sets an environment for csc but my installation
of the Framework (v1.1.4322) contains no batch or command
files of any description. I need to get this compiling
in an environment without the full SDK or VS.Net - only
the .Net Framework will be available in the target
environment (should be enough...).


Do you have a short but complete example which demonstrates the
problem? It sounds very odd to me. Are you referencing any assemblies
other than the "built-in" ones?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

Do you have a short but complete example which demonstrates theproblem? It sounds very odd to me. Are you referencing any assembliesother than the "built-in" ones?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.


I am using the following "built-ins" across various
classes:

Microsoft.Win32
System
System.Collecti ons
System.Componen tModel
System.Data
System.Diagnost ics
System.Drawing
System.IO
System.Runtime. InteropServices
System.Security
System.Security .Permissions
System.Text
System.Text.Reg ularExpressions
System.Threadin g
System.Windows. Forms
System.Xml

It just occurred to me that one of my classes makes a
call to an unmanaged Windows API that is not available in
the .Net Framework - could this be a factor?

Here is the declaration:
----------------------------------------------------------
[DllImport("kern el32.dll",CharS et=CharSet.Auto ,
SetLastError=tr ue)]

[return:MarshalA s(UnmanagedType .Bool)]

private static extern bool SetEnvironmentV ariable(string
lpName, string lpValue);
----------------------------------------------------------

I compile with the following command line:
csc /out:myapp.exe /win32icon:myico n.ico /target:winexe
*.cs

The .cs files in the current directory include all forms
and classes for the app as well as the AssemblyInfo.cs
created by the IDE.

I can't really give you a complete example that would
also be short! Suffice to say though that apart from that
API call everything else is bog standard - no funny
stuff, just calls to Framework objects. My main form
uses a TreeView control, a DataGrid, and a couple of
buttons - pretty simple. It parses some XML and
populates the TreeView with node objects of my own class
that inherits from TreeNode. Once the tree is built you
can launch command-line sessions based on parameters
supplied by the selected tree node.
Nov 15 '05 #3
Andrew Warren <an*******@disc ussions.microso ft.com> wrote:
I am using the following "built-ins" across various
classes:
<snip>

Hmm... they all look okay.
It just occurred to me that one of my classes makes a
call to an unmanaged Windows API that is not available in
the .Net Framework - could this be a factor?
I wouldn't have thought so...
I can't really give you a complete example that would
also be short!


Have you tried? For instance, have you tried writing an app that pretty
much *just* does the unmanaged API call? If that works, you can rule
that out as a reason for the failure.

The other thing you could try is wrapping the Application.Run call in a
try/catch block, and logging more details of the exception to a file.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
Andrew : when you compile via the command line, you must include references
yourself.. For example, your application references Microsoft.Win32 ... so
make sure on your "csc" line, you include
"/r:Microsoft.Win 32.dll" or whatever the assembly name is that that's
defined in. Do this for all assemblies you're referencing.

"Andrew Warren" <an*******@disc ussions.microso ft.com> wrote in message
news:06******** *************** *****@phx.gbl.. .

Do you have a short but complete example which

demonstrates the
problem? It sounds very odd to me. Are you referencing

any assemblies
other than the "built-in" ones?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.


I am using the following "built-ins" across various
classes:

Microsoft.Win32
System
System.Collecti ons
System.Componen tModel
System.Data
System.Diagnost ics
System.Drawing
System.IO
System.Runtime. InteropServices
System.Security
System.Security .Permissions
System.Text
System.Text.Reg ularExpressions
System.Threadin g
System.Windows. Forms
System.Xml

It just occurred to me that one of my classes makes a
call to an unmanaged Windows API that is not available in
the .Net Framework - could this be a factor?

Here is the declaration:
----------------------------------------------------------
[DllImport("kern el32.dll",CharS et=CharSet.Auto ,
SetLastError=tr ue)]

[return:MarshalA s(UnmanagedType .Bool)]

private static extern bool SetEnvironmentV ariable(string
lpName, string lpValue);
----------------------------------------------------------

I compile with the following command line:
csc /out:myapp.exe /win32icon:myico n.ico /target:winexe
*.cs

The .cs files in the current directory include all forms
and classes for the app as well as the AssemblyInfo.cs
created by the IDE.

I can't really give you a complete example that would
also be short! Suffice to say though that apart from that
API call everything else is bog standard - no funny
stuff, just calls to Framework objects. My main form
uses a TreeView control, a DataGrid, and a couple of
buttons - pretty simple. It parses some XML and
populates the TreeView with node objects of my own class
that inherits from TreeNode. Once the tree is built you
can launch command-line sessions based on parameters
supplied by the selected tree node.

Nov 15 '05 #5
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote:
Andrew Warren <an*******@disc ussions.microso ft.com> wrote:
I am using the following "built-ins" across various
classes:


<snip>

Hmm... they all look okay.


I've just looked at them again - they look like namespaces, not
assemblies. What do you have under the References section of your
project?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Philip Rieck <st***@mckraken .com> wrote:
Andrew : when you compile via the command line, you must include references
yourself.. For example, your application references Microsoft.Win32 ... so
make sure on your "csc" line, you include
"/r:Microsoft.Win 32.dll" or whatever the assembly name is that that's
defined in. Do this for all assemblies you're referencing.


Microsoft.Win32 is actually a namespace, not an assembly. The default
response file for csc automatically adds references for all these
assemblies:

Accessibility.d ll
Microsoft.Vsa.d ll
System.Configur ation.Install.d ll
System.Data.dll
System.Design.d ll
System.Director yServices.dll
System.dll
System.Drawing. Design.dll
System.Drawing. dll
System.Enterpri seServices.dll
System.Manageme nt.dll
System.Messagin g.dll
System.Runtime. Remoting.dll
System.Runtime. Serialization.F ormatters.Soap. dll
System.Security .dll
System.ServiceP rocess.dll
System.Web.dll
System.Web.Mobi le.dll
System.Web.Regu larExpressions. dll
System.Web.Serv ices.dll
System.Windows. Forms.Dll
System.XML.dll

Only assemblies not in the above list need to be explicitly referenced.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7
Sorry - by "whatever that's defined in" -- I should have said "The assembly
that that namespace is defined in"

Since Andrew said that he's trying to do this without installing the SDK,
I'm wondering if he has no default response file, and so will have to
manually add references to all the referenced assemblies when he does a
compile.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Philip Rieck <st***@mckraken .com> wrote:
Andrew : when you compile via the command line, you must include references yourself.. For example, your application references Microsoft.Win32 ... so make sure on your "csc" line, you include
"/r:Microsoft.Win 32.dll" or whatever the assembly name is that that's
defined in. Do this for all assemblies you're referencing.


Microsoft.Win32 is actually a namespace, not an assembly. The default
response file for csc automatically adds references for all these
assemblies:

Accessibility.d ll
Microsoft.Vsa.d ll
System.Configur ation.Install.d ll
System.Data.dll
System.Design.d ll
System.Director yServices.dll
System.dll
System.Drawing. Design.dll
System.Drawing. dll
System.Enterpri seServices.dll
System.Manageme nt.dll
System.Messagin g.dll
System.Runtime. Remoting.dll
System.Runtime. Serialization.F ormatters.Soap. dll
System.Security .dll
System.ServiceP rocess.dll
System.Web.dll
System.Web.Mobi le.dll
System.Web.Regu larExpressions. dll
System.Web.Serv ices.dll
System.Windows. Forms.Dll
System.XML.dll

Only assemblies not in the above list need to be explicitly referenced.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #8
Philip Rieck <st***@mckraken .com> wrote:
Sorry - by "whatever that's defined in" -- I should have said "The assembly
that that namespace is defined in"

Since Andrew said that he's trying to do this without installing the SDK,
I'm wondering if he has no default response file, and so will have to
manually add references to all the referenced assemblies when he does a
compile.


I wouldn't think so. Bear in mind that he *is* managing to compile it.
It's *running* it that is causing problems. Missing an assembly
reference would mean a failure to compile, not to run.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #9
I ended up logging a call with Microsoft to resolve this
and it turns out that the problem lies with attaching
custom icons to the forms... as soon as the icons are
removed it compiles fine with csc!

There is a workaround - the .resx files for the forms can
be compiled to .resource files using resgen.exe and then
compiled with csc. The downside of this is that it does
not meet my requirement of being able to compile the app
using only the .Net Framework - resgen is part of Visual
Studio.

Still, at least I know what the problem is now!

Thanks for your responses and suggestions. I'll let you
know when I hit on the final solution.
Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2059
by: rforman1 | last post by:
I have found many threads with this question asked and ostensibly answered, but none with an example of how exactly to do it. Help! I know that in order to set up the values of command line arguments from within the IDE, I go to Project Properties, Configuration Properties, and then the text box labeled "Command Line Arguments" under the label "Start Options." But what exactly do I put into that text box? What I want to do is set up a...
2
453
by: aladdin | last post by:
I use outside .jpg picture files in a Windows Form project. I try to compile use csc.exe at command line. I use resgen.exe to generate a resource file like: resgen.exe Form1.resx MyNameSpace.MainForm.resources then use csc to compile: csc /nologo /t:winexe /out:app1.exe /res:MyNameSpace.MainForm.resources /win32icon:App.ico *.cs The output exe file has the same size as compiled in VS.NET IDE, however, at runtime the program still...
5
14020
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to VIS.DLL via Visual Studio, with no problems: ------ Rebuild All started: Project: VIS, Configuration: Debug .NET ------ Preparing resources... Updating references...
4
7498
by: Brett | last post by:
I have recently purchased Visual C++ . Net compiler and i am trying to compile a project that i had working in Visual C++ 6.0. When I compile, I am receiving the warning: cl : Command line warning D4025 : overriding '/EHs' with '/EHa' I have specifically asked for the /EHsc switch because that is what I require.
6
1467
by: Todd A | last post by:
If I use the following in my code behind page: Public Class _Default Inherits System.Web.UI.Page The page will compile with no errors from the command line compiler (vbc.exe) But, If I insert my own base page to inherit from, say,
1
1579
by: Matt Creely | last post by:
I'm using the vbc.exe to compile a .dll automatically for me. I have all my framework references and imports setup correctly. And it will compile just fine, with a few lines of code commented out. Here's the problem. I have a vb class in my project("gamelan") called "Utilities". It's a public class, with a bunch of public shared methods I use through out the site. So when I try to compile, I get this error: ...
5
3402
by: clsmith66 | last post by:
I've been asked to find out if a project is possible, but I'm not having much luck finding the information I need, I hope some one can help. I need to see if I can build a windows service on the fly customized to a specific client. Is it possible to run the VS command line tool through another application (VB.NET)? I'm thinking I can run the tools as a process and pass the necessary parameters to the process, but I'm not sure how to go...
0
1402
by: chandan agarwal | last post by:
hi I have been given the task of building vc++ programs at the command line using make software. i have installed gnu make-3.81 version. i was able to build and run makefiles for turbo c++. but when i tried it for vc++ i faced a lot of problems. i found that vc++ has its own linker link and compiler cl. i am giving u a makefile tht was made for turbo c++. can u tell me what changes to i need to do make in it to make it run at the...
3
4571
by: Tom Baxter | last post by:
I just set up VS 2008 B2 and did a simple command line compile from the VS command prompt. I received this warning: warning CS1668: Invalid search path 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib' specified in 'LIB environment variable' -- 'The system cannot find the path specified. ' When I checked, sure enough, the "lib" directory is not present'. Perhaps I
0
8345
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8273
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8789
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8693
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8456
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8570
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2694
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1584
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.