0

I'm developing my ASP.NET 5 app using Visual Studio 2015. There is no problem at all since RC1 with working with multiple projects in one solution, and so on..

But for a few days I have to work with VS Code and I'm not sure how to solve missing classes problem. Let's say I have solution with project A and project B. They have it's own classes inside. In previous versions of ASP.NET all files have been referenced in .csproj file, but now, my .xproj files are nearly empty. There are no direct paths to files. And in my project A I've created new classes, they have all correct namespaces, project B has a reference to A (even my controller in project B uses classes from same A's namespace!), but there is a compiltion error which says that my classes cannot be found in project A :/

I thought that with VS Code I have to add some kind of references in project, to notify compiler about that new files,but I cannot find a correct place to do it. Any ideas?

1 Answer 1

2

You do this in the project.json file.

{
  "dependencies": {
    "ProjectA": "1.0.0-*"
  }
}

You declare the dependency. If the source is available in the solution folder, it will find it and use it. If the source isn't available, it can pull down a NuGet package that matches the version number. The documentation I linked to above provides more information about this process.

Once you have a dependency registered, you can refer to the public classes in your project. You'll need to fully qualify the dependencies (use the full namespace) or add a using <namespace> directive at the top of your file.

Sign up to request clarification or add additional context in comments.

4 Comments

I know how to reference project A to project B, but I'm talking about referencing classes to projects. Like in previous versions of ASP.NET / C# class library where each project had it's own .csproj file with paths to classes inside it. AFAIK it's not JAVA where all you have to do is to put file in correct folder.
There's no need for the proj file to reference files. That's part of the beauty of the new system. If the file is present in the project, it gets compiled, unless specifically told not to by a directive in the project.json file.
Wow... so it's a lot more like JAVA now :P So maybe I have typo in file names or something... I just needed a confirmation that creating a new file under correct namespace is all what I need.
It's not just about the correct namespace. It also needs to be in a project in the solution folder, or there's some other options. I suggest you use Visual Studio 2015 and compare what it does to what you're doing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.