Home > Software engineering >  visual studio community 2022 not building files before debugging
visual studio community 2022 not building files before debugging

Time:12-17

Recently I wiped my pc and reinstalled visual studio community 2022. Before re-installation, whenever I made some changes in my projects, I would press F5 to enter debug and it would build all files before entering debug mode.

To make it clear, I can manually build the files every time via pressing ctrl F7, but it is just a work around.

Now, after making changes and pressing F5 it ignores those changes and runs the last build.

I went over the settings and made sure everything matches with another install I have on a second machine.

I found this post Visual Studio Screenshot

CodePudding user response:

Possible cause 1

I think it's because your file module.cpp is seen as a text file and not as a source file by VS (Visual studio), and therefore VS won't rebuild your project after it is changed.

If it's a source file it should be refered in YourProject.vcxproj as:

  <ItemGroup>
    <ClCompile Include="module.cpp" />
  </ItemGroup>

So, in order to add new source files cleanly you want to use the VS's built-in "add class" (shift alt c) and use those files.

In your case, your can repair your project by editing your vcxproj file as in my example.

Possible cause 2

Including directly the cpp file can be problematic. Instead you want to have a .h .cpp pair, and put your declaration in .h and your code in either of them, and include the .h in your main source.

  <ItemGroup>
    <ClCompile Include="module.cpp" />
    <ClCompile Include="main.cpp" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="module.h" />
  </ItemGroup>

In that case, the binaries were updated when the source were, when I asked to debug (F5).

module.h:

#pragma once
#include <iostream>
using namespace std;

class module
{
public:
    void func1()
    {
        cout << "Now it works !" << endl;  // change this line
    }
};

module.cpp:

#include "module.h"
  • Related