Skip to content

Ignore PROJECT.JSON when using .CSPROJ #394

Closed
@bchavez

Description

@bchavez

Hi,

I have a serious problem after upgrading to VS 2015 Update 1 RTM.

I am trying to do cross-platform development for my RethinkDB Driver for both CoreCLR/DNX and full .NET 4.5 framework.

I don't want to convert everything to a DNX build project because the CoreCLR/DNX stuff has not RTM'd. So, I'd just like to use standard RTM tools when developing the .NET 4.5 target, then, later when Visual Studio is closed, do dnu build _as a separate thing_.

When I have .CSPROJ open in Visual Studio and I try to compile, I get an error that was not here prior to Update 1:

Your project.json doesn't have a runtimes section. 
You should add '"runtimes": { "win": { } }' to your project.json and 
then re-run NuGet restore. RethinkDb.Driver

Okay... So I attempt to add:

"runtimes": { "win": { } }

Q1: why do I need this "win" tag since I'm doing cross-platform targeting with CoreCLR? I am not, in any way, targeting "windows" with CoreCLR/DNX).

So, I place the tag inside project.json, but still no dice. Now I'm getting even more errors:

Some packages are not compatible with DNXCore,Version=v5.0 (win).           0   
System.Runtime.Extensions 4.0.11-beta-23516 provides a compile-time reference assembly for System.Runtime.Extensions on DNXCore,Version=v5.0, but there is no run-time assembly compatible with win.            0   
System.Net.Primitives 4.0.11-beta-23516 provides a compile-time reference assembly for System.Net.Primitives on DNXCore,Version=v5.0, but there is no run-time assembly compatible with win.            0   

Now it looks like this new "win" runtime tag is causing even more problems. Can someone tell me why MSBUILD is so unhappy now?

Even better, can someone tell me how to force _MSBUILD + VS + NUGET_ to 🚫 STOP 🚫 probing for project.json when I have my classic .CSPROJ open? I _do not_, want project.json even being considered or looked at when I have my classic .CSPROJ open in Visual Studio. I'd prefer my PACKAGES.CONFIG ✅ considered when my classic project is open. I don't understand why the tooling from both DNX (project.json) and CSPROJ are conflicting. IMHO, these should be two completely different things at this stage.

Feel free to fork or download the project. My sources here: https://github.com/bchavez/RethinkDb.Driver

There are two solutions:

  • RethinkDb.Driver.Dnx.sln - DNX Project Solution
  • RethinkDb.Driver.sln - Classic .csproj Solution

Thanks,
Brian

Activity

bchavez

bchavez commented on Dec 7, 2015

@bchavez
Author

Okay, I sort of solved this by downgrading .csproj Toolsversion to 4.0 (from 14.0) <Project ToolsVersion="4.0".

weshaggard

weshaggard commented on Dec 7, 2015

@weshaggard
Member
Pilchie

Pilchie commented on Dec 7, 2015

@Pilchie
Member

project.json and .csproj files are NOT two differently things. project.json is used by more than just DNX. It can also be used in conjunction with .csproj files as a replacement for packages.config, to allow .csproj files to take advantage of features like transitive dependencies, build time resolution of assets, etc.

The reason you are being prompted to add a runtime section is because the build time asset resolution is trying to copy assets from your dependencies to allow you to run, but it needs to know what assets you want to copy.

Having a project.json meant to be used for DNX in the same directory as a packages.config to be used by msbuild isn't something that's supported today, but you can have two different project.json files, one for msbuild and one for DNX. To do that, create a <projectname>.project.json (where <projectname> is the name of your .csproj. This will allow you to specify the existing framework from your .csproj, instead of of DNX.

Finally, if you are building a library and you don't want to copy runtime assets to your output directory, you can add <CopyNuGetImplementations>false</CopyNuGetImplementations> to your .csproj, in which case you won't need a runtimes section in your <projectname>.project.json.

Hope this helps.

(Also tagging @yishaigalatzer and @ericstj)

bchavez

bchavez commented on Dec 7, 2015

@bchavez
Author

Thanks @Pilchie

be used in conjunction with .csproj files as a replacement for packages.config

Thank for explaining this: I'll migrate off packages.config

The reason you are being prompted to add a runtime section is because the build time asset resolution is trying to copy assets from your dependencies to allow you to run, but it needs to know what assets you want to copy.

If I understand correctly, then, how do I tell the build time asset resolution that I only want outputs for net45 full framework right now when I build the solution in VS2015 and not bother with any DNX stuff?

Again, thanks for your help

bchavez

bchavez commented on Dec 7, 2015

@bchavez
Author

If I understand correctly, then, how do I tell the build time asset resolution that I only want outputs for net45 full framework right now when I build the solution in VS2015 and not bother with any DNX stuff?

Maybe, specify runtime: { "win":{}} in name.project.json, but leave it out in the root project.json?

Pilchie

Pilchie commented on Dec 7, 2015

@Pilchie
Member

I edited my markdown so that the xml doesn't disappear in in the rendered output.

Right - also, name.project.json should just have a single entry like net451 in the frameworks section.

bchavez

bchavez commented on Dec 7, 2015

@bchavez
Author

Fantastic. Thank you. That seems to have solved everything. Once again, happily compiling! I'm sure other will find this information really useful. Just had to do one last solution wide "nuget restore" after the changes.

bchavez

bchavez commented on Dec 11, 2015

@bchavez
Author

This is a bit strange. So, check this out:

  • Everything was working fine when I closed the issue. I could compile fine in VS2015 Update 1 after adding name.project.json.
  • I added one dependency on System.Threading.Timer to project.json:
"dnxcore50": {
      "dependencies": {
        //
        "System.Threading.Timer": "4.0.1-beta-23516"
      },
  • Build, but got the error:
Your project.json doesn't have a runtimes section. 
You should add '"runtimes": { "win": { } }' to your project.json and 
then re-run NuGet restore. RethinkDb.Driver
  • Ok. So, I back out and remove the line System.Threading.Timer, save, build-clean, and "Restored NuGet" packages. Even restarted Visual Studio and a _still_ get an error message.

So, now _what_ is going on? I have name.project.json with the necessary "runtime", and a project.json without any runtimes as we discussed few days ago.

I dunno, but to me it seems natural to revert my 1 line edit should get me back to where I was but I cannot back out of a 1-line edit. I cannot get rid of this error. 👎. Back to square one in this original issue.

Latest code, "name.project.json" & "project.json" files here:
https://github.com/bchavez/RethinkDb.Driver/tree/master/Source/RethinkDb.Driver

CI server's Build Error:
https://ci.appveyor.com/project/bchavez/rethinkdb-driver/build/282#L654

"C:\projects\rethinkdb-driver\Source\RethinkDb.Driver.sln" (Rebuild target) (1) ->
"C:\projects\rethinkdb-driver\Source\RethinkDb.Driver.Tests\RethinkDb.Driver.Tests.csproj" (Rebuild target) (2) ->
"C:\projects\rethinkdb-driver\Source\RethinkDb.Driver\RethinkDb.Driver.csproj" (default target) (3:2) ->
(ResolveNuGetPackageAssets target) -> 
  C:\Program Files (x86)\MSBuild\Microsoft\NuGet\Microsoft.NuGet.targets(109,5): error : Your project.json doesn't list 'win' as a targeted runtime. You should add '"win": { }' inside your "runtimes" section in your project.json, and then re-run NuGet restore. [C:\projects\rethinkdb-driver\Source\RethinkDb.Driver\RethinkDb.Driver.csproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:04.14
bchavez

bchavez commented on Dec 11, 2015

@bchavez
Author

I deleted these *.lock.json files and it seems to build again. I still think this is a symptom of a larger problem.

  1. I delete _ALL_ lock files (and ensure NO lock files exist in the build DIR), I can run

    msbuild source\RethinkDb.Driver.sln, _BUILD SUCCESS_ ✅

  2. Restore Packages from Visual Studio 2015 Update 1, generates RethinkDb.Driver.project.lock.json, and the command:

    msbuild source\RethinkDb.Driver.sln _BUILD FAIL_ ❌ with error message below:

Your project.json doesn't list 'win' as a targeted runtime. You should add '"win": { }' 
inside your "runtimes" section in your project.json, and then re-run NuGet restore.
    RethinkDb.Driver            

So, ironically, Restore Packages breaks the build. 🎱

jasonmalinowski

jasonmalinowski commented on Dec 19, 2015

@jasonmalinowski
Member

So there's a two things there:

  1. I've filed MSBuild targets should condition on project.json's existence, not project.lock.json's existence NuGet/Home#1859 to address your immediate point that we're using the existence of the lock file to figure out whether we are looking for NuGet packages or not. In your case, the first build should fail with some sort of "you didn't restore packages" error. In your case, the build succeeded but didn't actually consume the packages you thought you referenced, so that isn't good.
  2. The error message is correct: you need to update your project.json to include that entry under runtimes. In Visual Studio 2015 RTM there was a bug that meant you could get away with win-anycpu in there, but that had many other problems. You should add the win entry, and remove win-anycpu if you don't care about building with RTM.

Since NuGet/Home#1859 is tracking the first strangeness you observed, and the second issue is addressed by updating your project.json as described, can you close this bug once you've confirmed you're unblocked?

bchavez

bchavez commented on Dec 19, 2015

@bchavez
Author

Hi @jasonmalinowski,

  1. I have project.json with all the necessary references.
  2. I have name.project.json with the runtimes: { "win-anycpu" } and "frameworks": { "net45":{}}.

This should work. But it does not. I think it's likely due to No.1 NuGet/Home#1859. But once NuGet/Home#1859 as you suggested is fixed, I fear I will be in a state where I will no longer be able to build this project. NuGet/Home#1859 actually allows me to build the project normally _without_ failing on this "runtimes" compiler error.

bchavez

bchavez commented on Dec 19, 2015

@bchavez
Author

Please feel free to checkout / clone the repo here:

https://github.com/bchavez/RethinkDb.Driver/tree/master/Source/RethinkDb.Driver

I have MSBuild hacks everywhere just trying to get this to build for net45 and dnx CoreCLR. All the msbuild hacks are inside this BauBild file

30 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Ignore PROJECT.JSON when using .CSPROJ · Issue #394 · dotnet/msbuild