# How to use cmake to generate Visual Studio .sln and .vcxproj

**URL:** https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878
**Category:** Usage
**Created:** [June 16, 2022, 5:14pm UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878 "2022-06-16T17:14:08Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![michaelk1](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/977dab/32.png) [@michaelk1](https://discourse.cmake.org/u/michaelk1)
#### Post date: [June 16, 2022, 5:14pm UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878/1 "2022-06-16T17:14:08Z")

</div>

Hi,

I am new to this forum, so an Hello to all of you.

My problem:

I try to generate VS .sln and .vcxproj files from existing cmake files using cmake. So i will be able to use VS without cmake.

But do not know how.

The examples i found are the other way around. From VS to cmake, this is not what i am looking for.

Any idea is very helpful.

Thanks in advance.

cua  
michael

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [June 16, 2022, 7:04pm UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878/2 "2022-06-16T19:04:55Z")

</div>

`cmake -B Builds -G 'Visual Studio 17 2022'`

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 16, 2022, 7:48pm UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878/3 "2022-06-16T19:48:26Z")

</div>

> [@michaelk1](#):
>
> I try to generate VS .sln and .vcxproj files from existing cmake files using cmake. So i will be able to use VS without cmake.

If I understand what you want in the end, CMake’s generated build systems still require CMake (at least to regenerate it if it changes). Additionally, CMake’s generated files are anchored to the absolute path used and is not relocatable.

---

<div class="post-metadata">

### Author: ![michaelk1](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/977dab/32.png) [@michaelk1](https://discourse.cmake.org/u/michaelk1)
#### Post date: [June 17, 2022, 5:30am UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878/4 "2022-06-17T05:30:03Z")

</div>

Thank you very much. I’ll try that and let you know what happened.

---

<div class="post-metadata">

### Author: ![michaelk1](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/977dab/32.png) [@michaelk1](https://discourse.cmake.org/u/michaelk1)
#### Post date: [June 17, 2022, 5:32am UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878/5 "2022-06-17T05:32:44Z")

</div>

Thanks for the answer:

my goal is: getting the VS project files to use within VS but without cmakes txt files. I want to have a clean VS environment.

cu

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [June 17, 2022, 5:35am UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878/6 "2022-06-17T05:35:10Z")

</div>

Why do you want to get VS files without cmake? And how exactly do you envision cmake helping you with that…? 🤔

You can just create a VS project file by hand and not use cmake. Not sure why you’d want to do that, though.

---

<div class="post-metadata">

### Author: ![michaelk1](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/977dab/32.png) [@michaelk1](https://discourse.cmake.org/u/michaelk1)
#### Post date: [June 17, 2022, 8:28am UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878/7 "2022-06-17T08:28:00Z")

</div>

Well,

I use an Open source Project, which has Many Modules and include Files(\> 200).  
I added my own Code, so the project has grown by a Factor of 3.

Every time the open source project ist modified by its developer, i have to  
merge my version with the developers.

Cu  
Michael

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 17, 2022, 10:37am UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878/8 "2022-06-17T10:37:00Z")

</div>

> [@michaelk1](#):
>
> Every time the open source project ist modified by its developer, i have to  
> merge my version with the developers.

Well, that’s part of being a fork. I would recommend working with upstream to help contribute the build system you’re using or accept that things are going to be different and have this updating on the task list for every rebase/merge.

---

<div class="post-metadata">

### Author: ![michaelk1](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/977dab/32.png) [@michaelk1](https://discourse.cmake.org/u/michaelk1)
#### Post date: [June 17, 2022, 10:51am UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878/9 "2022-06-17T10:51:03Z")

</div>

Well,

the project is in use within our company. over 1000 users are using it. The contracts of our company with the customers let us not freeze the project at a special point. We have to manage every change of the origin code to be up to date.

cu

---

<div class="post-metadata">

### Author: ![lu994146765](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lu994146765/32/2978_2.png) [@lu994146765](https://discourse.cmake.org/u/lu994146765)
#### Post date: [December 2, 2022, 8:55am UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-generate-visual-studio-sln-and-vcxproj/5878/10 "2022-12-02T08:55:01Z")

</div>

Hello  
I also encountered the same problem,  
I tried to use scripts to change the absolute paths in the sln and vcxproj files generated by cmake to relative paths, but it was still not fully satisfied,  
did you solve it?
