Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 13:56

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C#].csproj Datei compilen ohne VS

Discussion on [C#].csproj Datei compilen ohne VS within the .NET Languages forum part of the Coders Den category.

Closed Thread
 
Old   #1
 
.тяµε.'s Avatar
 
elite*gold: 1
Join Date: Jun 2010
Posts: 1,624
Received Thanks: 563
[C#].csproj Datei compilen ohne VS

Heyho ...
Da ich an einem Programm arbeite, bei dem man eine .exe erstellen soll(in C#), muss ich nun wissen wie man eine - .csproj Datei compilt...
Ich habe schon in Google vieles durchsucht, aber nichts gefunden ..

Ich hab mal was von einer MSBuild gelesen aber leider auch nicht genug gefunden...

Kennt sich da jemand aus? Wäre euch sehr dankbar

LG!
.тяµε. is offline  
Old 10/19/2011, 16:24   #2
 
XxharCs's Avatar
 
elite*gold: 34
Join Date: Apr 2011
Posts: 1,475
Received Thanks: 1,228

Ist kein Visual Studio aber ein C# Compiler/IDE

mfg
XxharCs is offline  
Old 10/19/2011, 16:35   #3
 
.тяµε.'s Avatar
 
elite*gold: 1
Join Date: Jun 2010
Posts: 1,624
Received Thanks: 563
Ich hab Visual C#... Ich will durch mein Programm (mit C# erstellt) ein anderes .csproj compilen...
.тяµε. is offline  
Old 10/19/2011, 16:46   #4
 
XxharCs's Avatar
 
elite*gold: 34
Join Date: Apr 2011
Posts: 1,475
Received Thanks: 1,228
So wie ich es jetzt verstehe meinst du, das dein Programm ein compiler für dein anderes projekt ist oder ? :OO

Das kommt drauf an wie du dein Programm gemacht hast..Also zB dein Programm ist eine konsolenanwendung und du nicht gecoded hast, das er sich das proket holt,dann kopierst du das projekt und fügst es in dein Programm. (Also das projekt ziehst du auf deine exe,damit dein Projekt compiled wird)

edit: sonst ka was du meinst und wie :O
XxharCs is offline  
Old 10/19/2011, 17:00   #5
 
.тяµε.'s Avatar
 
elite*gold: 1
Join Date: Jun 2010
Posts: 1,624
Received Thanks: 563
Das haste richtig verstanden

Ich kann es als Konsole oder als Win-Form machen ^^...
Nur habe ich dich jetzt nicht so richtig verstanden o.0
.тяµε. is offline  
Old 10/19/2011, 19:02   #6

 
boxxiebabee's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 1,222
Received Thanks: 500
Codedome wäre vll. für dich interessant. Damit kannst du Code dynamisch kompilieren.
boxxiebabee is offline  
Thanks
1 User
Old 10/19/2011, 20:16   #7
 
.тяµε.'s Avatar
 
elite*gold: 1
Join Date: Jun 2010
Posts: 1,624
Received Thanks: 563
Quote:
Originally Posted by Lizzaran View Post
Codedome wäre vll. für dich interessant. Damit kannst du Code dynamisch kompilieren.
Ich schau es mir mal an, aber kann man da mehrere Klassen in eine .exe packen und erstellt das nur Konsolenanwendungen?
Aber thx schonmal
.тяµε. is offline  
Old 10/20/2011, 10:40   #8
 
elite*gold: 0
Join Date: Nov 2007
Posts: 62
Received Thanks: 17
@.тяµε.:

Indeed you may use Codedome! I also have an example for you. So let's create a new console app.
Ofcourse you can use WinForms but console app. suits better here just for now.

Now we need following namespaces added to our imports:
Code:
using System.CodeDom.Compiler;
using Microsoft.CSharp;
I suppose you have a test .cs file you want to compile, if not I wrote one for you.
Just open Notepad and save it as Sample.cs or something:

Code:
using System;

namespace Program
{
    public class MyProgram
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.ReadKey(true);
        }
    }	
}
Now change back to your console app. project and add new method we
need later in order to compile our .cs file.

Code:
/// <summary>
/// Compiles the specified target.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="outputFile">The output file.</param>
public static void Compile(string target, string outputFile)
{
    // Add your references here.
    //
    string[] references = new[] {
        "System.dll"
    };

    var parameters = new CompilerParameters()
    {
        OutputAssembly = outputFile,
        GenerateExecutable = true,
        TreatWarningsAsErrors = true,
        CompilerOptions = "/optimize"
    };

    parameters.ReferencedAssemblies.AddRange(references);

    var compiler = new CSharpCodeProvider();
    var result =
        compiler.CompileAssemblyFromFile(parameters, target);

    if (result.Errors.HasErrors)
    {
        var output = "Failed to compile: ";

        foreach (var error in result.Errors) 
        {
            output += error.ToString();
        }

        throw new ApplicationException(output);
    }
}
Now call it just like this:

Code:
Compile("Sample.cs", "Something.exe");
where Sample.cs your source file and Something.exe your output file.
PS. Don't forget to catch exceptions.

@EDIT:
If you want to compile multiple files then change the target parameter type in my method to string[].

Now call it like this:

Code:
var targets = new[] {
    "Sample.cs",   // Main class that calls all subclasses.
    "Class1.cs",
    "Class2.cs"
};

Compile(targets, "Something.exe");
OR

Code:
Compile(new[] { "Sample.cs", "Class1.cs", "Class2.cs" }, "Something.exe");

Best regards,

Demon-777
Demon-777 is offline  
Thanks
1 User
Old 10/20/2011, 15:05   #9
 
.тяµε.'s Avatar
 
elite*gold: 1
Join Date: Jun 2010
Posts: 1,624
Received Thanks: 563
Thank you!
That helps me a lot
With your example everything works perfect.
But with my file, the program has always an error :/ :



Source(XNA 4.0 File ):
Code:
using System;

namespace Program
{
    public class Program
    {
        public static void Main(string[] args)
        {
            using (Game1 game = new Game1())
            {
                game.Run();
            }
        }
    }
}


Game1.cs

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Program
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}



PS: Sry for my bad english





Edit:

~closerequest hab es!
Ein großes Danke an Demon-777, der mir sogar noch per pn geholfen hatte !
.тяµε. is offline  
Closed Thread


Similar Threads Similar Threads
Patcher bei einem P-Server ohne .bin datei umgehen
12/24/2010 - Metin2 Private Server - 2 Replies
Hallo liebe com , ich habe folgendes problem: Ich weiß wie man patcher umgeht wie zb bin in exe umbennenen oder start.bat <start metin2client.bin>... aber bei Survival-World2 finde ich die bin datei einfach nicht ... ich habe mir einen 1 hit gemacht und er läuft auch auf vielen servern nur da nicht , denn wenn ich die pc.epk und eix ersetze da spiel starte patcht der patcher nur die 1-100.jpg dateien aber im spiel sind die rassen die in pc.epk vorkommen z.b. männlicher Krieger nicht...
[How2] Windows Style ohne Datei Patchen
11/08/2010 - Tutorials - 14 Replies
Hallo, hab mal ein Video gemacht ( ich weiß meine stimme is shice) YouTube - Style Selector
SF ohne Game datei ?
09/20/2010 - Metin2 Private Server - 4 Replies
Nabend, Habe neue SF bekommen mit mehreren CH's aber als ich meine game datei hochgeladen habe, merkte ich das der server sie nicht angenommen hat. Danach habe ich die alte game datei in share_data gelöscht doch server ging ganz normal an Kann mir das jmd erklären? Wie kann ein Server ohne game an gehen?
[How to]Ohne Surakopf Datei connecten (Erweitert)
02/02/2010 - Metin2 PServer Guides & Strategies - 12 Replies
Hi, also ich hab grad mal mit der Serverinfo.py rumgespielt und versucht mehrere Server zu erstellen (wie Mosha, Legoria..) die zu verschiedenen IP´s connecten d.h. ihr öffnet euren Clienten und dann seht igr da als Auswahl FantasMt2 Black-Planet o.Ä. je nachdem halt wie ihr euren Clienten moddet. So nun zum TuT Als erstes braucht ihr die Serverinfo.py die bekommt ihr indem ihr die Root Dateien aus dem Pack Ordner entpackt oder ihr habt einen Clienten (z.B. den von NeonBlue) wo das...
[Frage] Markierte Datei ohne Name löschen?
05/13/2009 - GW Bots - 3 Replies
edited



All times are GMT +1. The time now is 13:58.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.