# Help with Visual Studio Generator

**URL:** https://discourse.cmake.org/t/help-with-visual-studio-generator/1957
**Category:** Usage
**Created:** [October 2, 2020, 7:34am UTC](https://discourse.cmake.org/t/help-with-visual-studio-generator/1957 "2020-10-02T07:34:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [October 2, 2020, 7:34am UTC](https://discourse.cmake.org/t/help-with-visual-studio-generator/1957/1 "2020-10-02T07:34:38Z")

</div>

I have a CMake project that works fine on Linux and which I am now porting to Windows, where I want to build from the command line using the Visual Studio C++ tools.

I initially used the Ninja generator on Windows but got this recurring error:

`mt.exe : general error c101008d: Failed to write the updated manifest to the resource of file "myProj.exe". The system cannot open the device or file specified.`

I think that error may be to do with multiple concurrent accesses of the manifest file so I am now using the Visual Studio generator instead as follows:

```
cmake -G "Visual Studio 15 2017" -A x64 -DPROJECT_VARIANT=MyVariant..\\..
cmake --build .

```

Is this a good method?

My CMakeLists.txt contains:

```
cmake_minimum_required(VERSION 3.12.0 FATAL_ERROR)

set (CMAKE_BUILD_TYPE "Release" CACHE
     STRING "Choose the type of build.")
message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'")

project(myProj LANGUAGES CXX C)

```

On Linux, this builds a Release build, by default, and the executable is in the root of the current directory. On Windows it builds a Debug build by default, in directory Debug/myProj.exe.

Why does it build in Debug mode when I have specified a default build type of Release?

How would I force it to build Release in the cmake command?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [October 2, 2020, 9:26am UTC](https://discourse.cmake.org/t/help-with-visual-studio-generator/1957/2 "2020-10-02T09:26:42Z")

</div>

Because `CMAKE_BUILD_TYPE` is ignored in case of generators supporting multiple configurations.

To control the build type in multi-config, use option `--config` of `cmake`:

```auto
cmake --build . --config Release

```

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [October 2, 2020, 11:00am UTC](https://discourse.cmake.org/t/help-with-visual-studio-generator/1957/3 "2020-10-02T11:00:18Z")

</div>

Thanks for your help. Your suggestion worked for my x64 build, but I need to build one variant as an x86 target (because it uses a vendor’s x86 library) so I specified:

```
cmake -G "Visual Studio 15 2017" -A x86 -DPROJECT_VARIANT=MyVariant ..\\..

```

but that resulted in:

```
Failed to run MSBuild command:

    C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/MSBuild.exe

```

So I guess that ‘-A’ specifies the build tools architecture to use rather than the target architecture?

How would I specify the target architecture please?

---

<div class="post-metadata">

### Author: ![vre](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@vre](https://discourse.cmake.org/u/vre)
#### Post date: [October 2, 2020, 11:32am UTC](https://discourse.cmake.org/t/help-with-visual-studio-generator/1957/4 "2020-10-02T11:32:03Z")

</div>

It’s `-A Win32` for x86 builds. See CMake documentation for Visual Studio 15 2017 [here](https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2015%202017.html)

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [October 2, 2020, 12:59pm UTC](https://discourse.cmake.org/t/help-with-visual-studio-generator/1957/5 "2020-10-02T12:59:46Z")

</div>

All working now. Thank you!

---

<div class="post-metadata">

### Author: ![Xelous](https://discourse.cmake.org/user_avatar/discourse.cmake.org/xelous/32/874_2.png) [@Xelous](https://discourse.cmake.org/u/Xelous)
#### Post date: [October 9, 2020, 8:59am UTC](https://discourse.cmake.org/t/help-with-visual-studio-generator/1957/6 "2020-10-09T08:59:50Z")

</div>

With the VS generator (certainly for 2019) you can force ONLY one of the debug or release configurations to be added to the vcxproj file being output but using:

set(CMAKE\_CONFIGURATION\_TYPES “Debug”)

You can then pass a variable in from your command line “-DmyVariant=Debug” and check it with

if (DEFINED myVariant AND ${myVariant} STREQUAL “Debug”)  
set(CMAKE\_CONFIGURATION\_TYPES “Debug”)  
else()  
set(CMAKE\_CONFIGURATION\_TYPES “Release”)   
endif()

Hope that helps, you can generate in VS and see just that one config in the build configurations list then, so should be fine when just passing it onto msbuild too.
