Avatar billede yellow Nybegynder
23. juli 2004 - 16:52 Der er 5 kommentarer og
1 løsning

Installere en service applikation uden VS.NET

Hejsa,

Jeg sidder og er ved at lave en windows service application i C#.

Som en start har jeg bare lavet en "hello world"-agtig service, men jeg har problemer med at få den installeret.

Jeg bruger bare en simpel editor, altså ingen VS.NET
Jeg kompilerer med:
csc /out:myService.exe myService.cs

Når man så skal installere den skriver jeg fra en cmd  prompt:
installutil C:\test\myService.exe

En del af outputtet jeg får er:
No public installers with the RunInstallerAttribute.Yes attribute could be found in the c:\test\myService.exe assembly.
Remove InstallState file because there are no installers.

Jeg har så fundet frem til at jeg mangler en projectinstaller class. Denne class er en man kan tilføje via UIet i VS.NET og den bliver compileret i forbindelse med at man kompilerer sit projekt i VS.NET.

MEN...hvad gør jeg når jeg nu ikke har VS.NET?
Jeg har lavet en projectinstaller.cs fil og har tilpasset den min service applikation, men hvad gør jeg med projectinstaller.cs filen for at kompilere den med csc command line kompileren?

Hmm, håber det giver lidt mening og at nogen kan hjælpe :-)


//Yellow
Avatar billede yellow Nybegynder
23. juli 2004 - 16:55 #1
Eller sagt på en enklere måde:
Jeg ønsker en step-by-step guide til hvordan jeg laver og installerer en hello-world service application i C# - UDEN VS.NET
Avatar billede snepnet Nybegynder
23. juli 2004 - 16:57 #2
Avatar billede snepnet Nybegynder
23. juli 2004 - 16:58 #3
Hov... jeg har jo klippet C# elementerne ud af det... Du får lige en her hvor C# delen er med.
Avatar billede snepnet Nybegynder
23. juli 2004 - 17:02 #4
Step 1 — Compiling Files with Namespaces Referenced by Other Files
This example starts with some simple code for the Stringer file. Stringer has a namespace called myStringer with a class called Stringer. The Stringer class contains a method called StringerMethod that writes a single line to the console.

[C#]
// Assembly building example in the .NET Framework SDK.
using System;
namespace myStringer
  {
  public class Stringer
      {
      public void StringerMethod()
        {
        System.Console.WriteLine("This is a line from StringerMethod.");
        }
      }
  }

Use the following command to compile this code:

[C#]
csc /t:module Stringer.cs

Specifying the module parameter with the /t: compiler option indicates that the file should be compiled as a module rather than as an assembly. The compiler produces a module called Stringer.netmodule, which can be added to an assembly.

Step 2 — Compiling Modules with References to Other Modules
This step uses the /addmodule compiler option. In this example, a code module called Client has an entry point Main method that references a method in the Stringer.dll module created in Step 1.

The following example shows the code for Client.


[C#]
using System;
using myStringer; //The namespace created in Stringer.netmodule.
class MainClientApp
{
  // Static method Main is the entry point method.
  public static void Main()
  {
      Stringer myStringInstance = new Stringer();
      Console.WriteLine("Client code executes");
      //myStringComp.Stringer();
      myStringInstance.StringerMethod();
  }
}

Use the following command to compile this code:

[C#]
csc /addmodule:Stringer.netmodule /t:module Client.cs

Specify the /t:module option because this module will be added to an assembly in a future step. Specify the /addmodule option because the code in Client references a namespace created by the code in Stringer.netmodule. The compiler produces a module called Client.netmodule that contains a reference to another module, Stringer.netmodule.

Note  The C# and Visual Basic compilers support directly creating multifile assemblies using the following two different syntaxes.
Two compilations create a two-file assembly:

[C#]
csc /t:module Stringer.cs
csc Client.cs /addmodule:Stringer.netmodule

One compilation creates a two-file assembly:
[Visual Basic]
vbc /out:Stringer.netmodule Stringer.vb /out:Client.exe Client.vb

[C#]
csc /out:Client.exe Client.cs /out:Stringer.netmodule Stringer.cs

Step 3 — Creating a Multifile Assembly Using the Assembly Linker
You can use the Assembly Linker (Al.exe) to create an assembly from a collection of compiled code modules.

To create a multifile assembly using the Assembly Linker

At the command prompt, type the following command:
al <module name> <module name> ... /main:<method name> /out:<file name> /target:<assembly file type>

In this command, the module name arguments specify the name of each module to include in the assembly. The /main: option specifies the method name that is the assembly's entry point. The /out: option specifies the name of the output file, which contains assembly metadata. The /target: option specifies that the assembly is a console application executable (.exe) file, a Windows executable (.win) file, or a library (.lib) file.

In the following example, Al.exe creates an assembly that is a console application executable called myAssembly.exe. The application consists of two modules called Client.netmodule and Stringer.netmodule, and the executable file called myAssembly.exe, which contains only assembly metadata . The entry point of the assembly is the Main method in the class MainClientApp, which is located in Client.dll.

al Client.netmodule Stringer.netmodule /main:MainClientApp.Main /out:myAssembly.exe /target:exe

You can use the MSIL Disassembler (Ildasm.exe) to examine the contents of an assembly, or determine whether a file is an assembly or a module.
Avatar billede yellow Nybegynder
23. juli 2004 - 17:17 #5
Smukt!

Compilede projectinstaller:
csc /t:module projectinstaller.cs

Compilede ServiceApp:
csc /addmodule:projectinstaller.netmodule /out:myService.exe myService.cs

Intstallerede myService:
installutil myService.exe

Og den kører i windows services :-)

Takker, smid et svar - var den der module jeg skulle bruge.
Avatar billede snepnet Nybegynder
23. juli 2004 - 17:24 #6
Det var jo alletiders :o)
Mvh
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester