简体   繁体   中英

One .NET solution with two projects (with different references), using the same source code?

This is the situation: I have an application that access some external hardware. To do that I use the API from the HW vendor in form of a .NET framework. No problem here, I just add a project reference to the framework and that's it.

But now I want to be able to build a "stand-alone" version of the application, that does the exact same thing except accessing the hardware. My intention was to create a new project in the same solution that uses the same source files. It shall not have the project reference to the Framework, and then I figured I could use some simple #define to disable the parts where the framework is accessed.

But I can't figure out how to do this. If I add a new project into the same solution, Visual Studio seems to copy the files (File->Add Existing) to the new project directory. And since I will continue to work on the files I really do not want to have duplicates of them.

The main problem is that the drivers needed is HUGE and the customer does not want to install them on all PCs, just on the single one that actually uses the HW.

I use Visual Studio .NET 2008 and C++, and the project is a Windows Forms app.

When you add the existing files, add them as links.

From the Add button drop-down list, select Add As Link .

添加为链接

This is described in the MSDN article How to: Add Existing Items to a Project .

I think it would be better to create a new Build Configuration rather than a completely separate project with the same source files. Essentially, Configuration is like having separate projects, where you can set it to Debug or Release, for instance. In your situation, create a new configuration, and modify the project settings for that condition (including references). Then you can flip between the two configurations. Get to the Configuration Manager from the Build menu. Any changes you make to project settings apply to the current configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM