Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Project file could not be loaded, data at root level is invalid, no XML in the project

Tags:

c#

.net

I am trying to run a hello world C# code from command line and this is the batch file. Tried searching for it but most of the questions are about the XML file reader, I am not reading any XML files.

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild "E:\a\c.cs" /p:Configuration=Debug;DeployOnBuild=True;PackageAsSingleFile=False;outdir=E:\a

and this is c.cs

class c {
    public static void Main() {
        System.Console.Clear();
        System.Console.WriteLine("hey");
        System.Console.ReadKey();
    }
}

and the error

enter image description here

like image 889
Achshar Avatar asked Nov 06 '15 21:11

Achshar


2 Answers

msbuild expects a project file or a solution file as input:

https://msdn.microsoft.com/en-us/library/ms164311.aspx

What you want to do is run the c# compiler directly:

Compiling/Executing a C# Source File in Command Prompt

like image 95
Russell McClure Avatar answered Nov 05 '22 03:11

Russell McClure


If you are running dotnet with the following command while running.

dotnet run --project [project_name].dll

You can run the following instead of the above command.

dotnet [project_name].dll
like image 41
Furkan Doğanay Avatar answered Nov 05 '22 02:11

Furkan Doğanay