# Visual Studio

version 9.5.0-20260327013305+0000

The Visual Studio Plugin generate files that are used by the Visual Studio IDE, thus making it possible to open the solution into Visual Studio (`File` - `Open` - `Project/Solution…​`).

What exactly the `visual-studio` plugin generates depends on which other plugins are used:

Table 1. Visual Studio Plugin behavior
Plugin | Description
--- | ---
None | Generates minimal solution file.
C++ Application | Adds a project representing the C++ application to the solution file.
C++ Library | Adds a project for each specified linkage representing the shared and/or static library to the solution file.

## Usage

build.gradle.kts

    plugins {
        `visual-studio`
    }

build.gradle

    plugins {
        id 'visual-studio'
    }

The Visual Studio Plugin adds a number of tasks to your project. The main tasks that you will use are the `visualStudio`, `cleanVisualStudio` and `openVisualStudio` tasks.

## Tasks

The following diagram shows the relationships between tasks added by this plugin.

Figure 1. Visual Studio Plugin default task graph

### Lifecycle Tasks

`visualStudio` — Task

  Depends on: `projectNameVisualStudioSolution` and all Visual Studio project file generation tasks

  Generates all Visual Studio configuration files.

`cleanVisualStudio` — Delete

  Depends on: all Visual Studio project and solution file clean tasks

  Removes all Visual Studio configuration files.

`openVisualStudio` - Task

  Depends on: `visualStudio`

  Open the Visual Studio solution inside the IDE.

### IDE Workspace Tasks

`projectNameVisualStudioSolution` - GenerateSolutionFileTask

  Generates the `.sln` file. This task is only available on the root project.

### IDE Project Tasks

#### C++ Application Plugin Tasks

`projectNameVisualStudioProject` — GenerateProjectFileTask

  Generates the `.vcxproj` file for the application component.

`projectNameVisualStudioFilters` — GenerateFiltersFileTask

  Generates the `.vcxproj.filters` file for the application component.

`mainVisualStudio` - Task (lifecycle)

  Depends on: `projectNameVisualStudioProject` and `projectNameVisualStudioFilters`

  Generates all Visual Studio project files for the application component.

#### C++ Library Plugin Tasks

`projectNameDllVisualStudioProject` — GenerateProjectFileTask

  Generates the `.vcxproj` file for the shared linkage of the `main` component.

`projectNameDllVisualStudioFilters` — GenerateFiltersFileTask

  Generates the `.vcxproj.filters` file for the shared linkage of the `main` component.

`projectNameLibVisualStudioProject` — GenerateProjectFileTask

  Generates the `.vcxproj` file for the static linkage of the `main` component.

`projectNameLibVisualStudioFilters` — GenerateFiltersFileTask

  Generates the `.vcxproj.filters` file for the static linkage of the `main` component.

`mainVisualStudio` - Task (lifecycle)

  Depends on: `projectNameDllVisualStudioProject` (for shared linkage), `projectNameDllVisualStudioFilters` (for shared linkage), `projectNameLibVisualStudioProject` (for static linkage) and `projectNameLibVisualStudioFilters` (for static linkage)

  Generates all Visual Studio project files for the library component.

## Configuration

The Visual Studio Plugin allows for some customization of the generated files. The following sections are shows the customization.

### Change solution generated file location

The location of the generated solution can be configured on the root project:

build.gradle.kts

    visualStudio {
        solution {
            solutionFile.setLocation(file("solution.sln"))
        }
    }

build.gradle

    visualStudio {
        solution {
            solutionFile.location = file('solution.sln')
        }
    }

### Change project generated files location

The location of the generated project files can be configured on any project:

build.gradle.kts

    visualStudio {
        projects.all {
            projectFile.setLocation(file("project.vcxproj"))
            filtersFile.setLocation(file("project.vcxproj.filters"))
        }
    }

build.gradle

    visualStudio {
        projects.all {
            projectFile.location = file('project.vcxproj')
            filtersFile.location = file('project.vcxproj.filters')
        }
    }