Introduction: Moving to the Visual Studio Project System
In my previous article, I commented on some of the benefits associated with having a project system when using Micro Focus Visual COBOL/Enterprise Developer. This time let's talk about what's actually required to move to the Visual Studio (VS) project system. The general process involves identifying which COBOL sources should be grouped logically together in a project and the compiler directives that are required to compile them.
Note that for people using the Eclipse Integrated Development Environment (IDE), the project system differs from VS, so I would recommend looking at the docs for those interested in Eclipse. The general process for creating a project is very similar between the two IDEs.
Before trying to move a COBOL application into a project, I would recommend creating a simple native COBOL project within VS or looking at the included product samples to get a feel for the structure of the project system.
Project structure and identifying logical groupings for a project
VS uses a solution file (.sln) as the top level element that gets loaded by the IDE. The solution file contains references to one or more projects (.cblproj) which actually contain references to the COBOL sources and configuration. On-disk, the folder structure of a typical VS project structure looks like the following (folders in bold)
There will be some generated folders (such as bin and obj) in the project directories, which get created during a build, so can be safely ignored for now. When I refer to the project directory, this is the folder that contains the project file; and equally the solution directory is the one containing the solution file.
The first step is to identify which COBOL sources are closely related and try to group them logically. Possible strategies may be to group by functionality, or programs that are used frequently together. In the example above, I've grouped all lending related programs together and all customer management programs together.
Whilst this is not strictly needed, it makes the workflow for the developer simpler. Files are easier to locate since they are ordered logically, and define some structure to the application. Note that project settings are shared by all COBOL sources that are contained within the project, so that may help decide where the project boundaries should be.
Creating a project and adding sources
Once logical boundaries have been decided, a developer then needs to create the solution and projects in VS. For this example, I will be creating a Native COBOL console application. To do so:
- Open Visual Studio
- Select File -> New -> Project...
- Select COBOL -> Native in the left tab
- Select Console Application as the project type
- Provide a project and solution name, then press OK
Once the solution and project file have been created, the COBOL sources then need to be added.
- Right click on the project node in Solution Explorer
- Select Add -> Existing Item...
- Locate files that should be added and press OK
- It is possible to select multiple files at once with the shift key
- Default behaviour is to copy the files into the project directory. If the developer does not want the file to be copied, then Add As Link can be used. This option is present in the Add dropdown.
To create any additional projects once a solution is defined, simply do the following:
- Right click on the Solution item in the Solution Explorer
- Select Add -> New Project...
Once the projects have been created and source files added, the typical next step is to locate any required copybooks. This can be done by setting the copybook paths in the project settings. Once set, the COBOL programs will be able to resolve copybooks with the copy statement.
- Double click on the Properties item under the Project node in Solution Explorer to open the project settings
- Configure the paths under the Copybooks tab
- Note that for certain project flavours, this may instead be under the Dependency Paths tab
It is possible to directly add copybooks to the project itself, though this is not the preferred method. Adding a copybook directly into a project is normally done when it will only be referenced by programs within the same project.
The post has covered how to create the basic project structure, add sources and configure the resolving of copybooks. In my next post I will be covering the configuration of directives.