La-comadreja
La-comadreja

Reputation: 5755

Adding namespaces to Visual Studio project

I am creating a Visual Studio solution and am trying to add namespaces Kafka.Client, Kafka.Client.Producers.Parititioning, Kafka.Client.IntegrationTests, etc. to a program file I've created with a Main() method. I have Kafka.Client and Kafka.Client.IntegrationTests in the References of this program file as per Solution Explorer. The code is as follows:

using Kafka.Client;
using Kafka.Client.IntegrationTests;
using Kafka.Client.Producers.Partitioning;
using Kafka.Client.Utils;
using Kafka.Client.ZooKeeperIntegration;

namespace ConsoleApplication2 {
    class Program {
        static void Main(string[] args) {
        //code here
        }
    }
}

The problem is that when I try to "Rebuild solution" or "debug solution", the aforementioned "using" lines give the error "The type or namespace name 'Kafka' could not be found (are you missing a using directive or an assembly reference?)" I've spent quite a long time on this and would appreciate some pointers about what I would need to do.

Upvotes: 3

Views: 17365

Answers (3)

La-comadreja
La-comadreja

Reputation: 5755

Thanks for trying to answer the questions. My problem was that the "Target application" was not the same for all the projects in my solution. Right-clicking on the referenced projects and selecting "Properties" enabled me to change the target application. Then I needed to rebuild the .dll files to run the program properly.

Upvotes: 0

AwokeKnowing
AwokeKnowing

Reputation: 8206

using doesn't actually "include" anything into your project. It just makes it so you don't always have to type out the full namespace. So the error is clearly in referencing the other project.

The Kafka project has to be built first. So first make sure you can successfully build the Kafka project.

if the Kafka is not in the same project, make sure you've add the the reference to the dll, and make sure "copy local" is true

to add the dll as a reference, right-click ConsoleApplication2 in the solution explorer, click add reference, then browse to and locate the actual dll output by the kafka project.

Upvotes: 3

Christian Phillips
Christian Phillips

Reputation: 18749

Sounds like these are separate class libraries or other projects. If that's the case, add a project reference from your main project and the using statements will then work.

The reason you want to add them as a project reference, and not a dll reference is that you'll likely switch back and forth from debug/release mode and you might end up with an outdated reference.

Upvotes: 1

Related Questions