.NET Core is here! We have been busy doing quite a bit of work with it. We have multiple client libraries for sending data to the Stackify API (for metrics, errors, logs, etc.). To ensure that all of our customers can send us data for their .NET Core apps, we have ported them over. So what’s the issue? How do you use both csproj and xproj?
We need csproj so we can build our apps with our existing toolchain, which relies on msbuild. We also need to reference some shared libraries across multiple different apps. Luckily, with Core 1.0 you can use both csproj and xproj at the same time by having different solution files.
Another major obstacle is the project.json file. This file is new for most developers working with .NET Core, but it isn’t actually new (it is also being utilized by universal Windows apps). If you add a project.json file to your application folder, your csproj will start trying to use it. It actually works great and can replace your packages.config and do a good job of setting project package dependencies for non core apps.
Another issue you run into is as soon as you add a .NET Core framework target to project.json, your csproj won’t know what the heck to do it with it.
The way to fix this is to have two “project.json” files:
Here is how our this sample project “Profiler.Models” looks on disk:
In this example, Profiler.Models.project.json is picked up by our csproj project. Our xproj for .NET Core properly reads the “project json,” and both can compile and build correctly. MSBuild can still build our normal solution with all our csproj based projects. Mission accomplished!
Here is what your “Profiler.Models.project.json” type file should contain. It is just a simple placeholder config.
{ “runtimes”: { “win”: {} }, “frameworks”: { “net45”: {} }}
I did see a little oddity when trying to add a new package dependency to my csproj. It added it to my Profiler.Models.project.json and things got a little weird, so watch out for that. I ended up deleting all my project.json files in the folder temporarily, adding the package to my csproj and then reverting my project.json deletes via git so they came right back. I kept my Profiler.Models.project.json clean and empty. You might be able to actually use it to manage all the dependencies for your cspoj.
If you would like to be a guest contributor to the Stackify blog please reach out to [email protected]