Moved from Microsoft/vscode#17028
From @Chrille2k
|Extension|Author|Version|
|---|---|---|
|csharp|ms-vscode|1.5.3|
Steps to Reproduce:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
}
}
1>Project "c:\path\to\project\project.json" on node 1 (Build target(s)).
1>MSBUILD : error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
What could possibly be wrong on row 1, position 1? File encoding issue?
Hi, I suspect that you allowed Visual Studio Code to generate a launch.json and tasks.json using the "MSBuild" template, which will not work with a .NET Core project.json project. Could you try the following for me?
Hi,
I followed your steps and VS Code recreated my tasks and launch files, the only difference turned out to be the line endings, before it was PC style, now it's UNIX style.
I tried changing to UNIX style in my project.json but with the same error.
Why this cryptic error message, seems like a simple formatting error?
MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
How can I easily create a project from scratch and compare the files generated for differences to my project?
Edit:
After downloading some sample code from github I got the exact same error, is there any issues with my environment?
Hmmm. Could you run dotnet -info at the command line and let me know the output?
I get the same issue. dotnet --info gives me:
.NET Command Line Tools (1.0.0-preview4-004233)
Product Information:
Version: 1.0.0-preview4-004233
Commit SHA-1 hash: 8cec61c6f7
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
Base Path: C:Program Filesdotnetsdk1.0.0-preview4-004233
Which I guess is the issue. I.e. preview 4 doesn't support project.json?
Yeah, that's what I thought was happening. You are correct that 1.0.0-preview4-004233 does not support project.json any longer, and I suspect that's the same problem @Chrille2k is seeing.
You can force an earlier version of the .NET CLI to be used by including the following in a "global.json" file in your project folder:
{
"sdk": {
"version": "1.0.0-preview2-003133"
}
}
Note that the version number must match a .NET SDK that you have installed on your machine. You can see what .NET SDKs you have installed by looking at %ProgramFiles%\dotnet\sdk (C:\Program Files\dotnet\sdk on my machine).
I'm pretty confident that this is the cause of the issue, but let me know if the solution above doesn't work for you.
Sorry for the delay, here is my info:
.NET Command Line Tools (1.0.0-preview4-004233)
Product Information:
Version: 1.0.0-preview4-004233
Commit SHA-1 hash: 8cec61c6f7
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\1.0.0-preview4-004233
So if not the project.json, should I use a csproj file instead?
See my solution above. That should address the problem for you if you want to stick with project.json for now.
I have nothing that keeps me to stick with that, just trying to run a C# core project.
In that case, you should be able to use dotnet migrate to migrate your application from project.json to .csproj.
Hi I am also encountering this issue when I am deploying my .net core project to azure.

Also, my bitbucket repo is initialized within the src folder, so it does not have the global.json which is outside of the src folder. So is there any way of setting azure to use the appropriate version of .net sdk? Should I have initialised the repo at the project root instead?
This repo is for issues with C# in VS Code, not necessarily for scripts at the command line. That said, the workaround is probably similar to what I wrote above here.
Thanks for the reply, the issue has been fixed. I didnt know that the global.json file can be put at the same directory level as the project.json file.
DustinCampbell's fix is also working for the azure publish error I was having.
Thanks!
this doesn't happen to work for VS 2015 does it? I'm trying to force an earlier version but package restore fails regardless of what I put in global.json :(
Yes, VS 2015 will respect the SDK version that you put in global.json.
It turns out it should, but it doesn't (due to a bug) - see https://github.com/dotnet/cli/issues/4248#issuecomment-259338964
Should we be expecting a fix? (other than the out-of-proc workaround :/ )
Not from this repo. This is the repo for C# in Visual Studio Code. You should ask the CLI folks.
will do, thx
Most helpful comment
Hi, I suspect that you allowed Visual Studio Code to generate a launch.json and tasks.json using the "MSBuild" template, which will not work with a .NET Core project.json project. Could you try the following for me?