Disable generation of metagen files in VS2010 - visual-studio-2010

When I build a C++/CLI project I get, among others, a file called "proj.exe.metagen".
Deleting it does not impair the execution of the generated executable so I'd rather have it not generated unless there is a good reason to have it around.
How can I disable generation of the metagen file?

Project > Properties > General > "Enable Managed Incremental Builds" setting. That's for VS2015 and also for VS2010.
Everybody likes fast builds so the default is Yes. If you select No then msbuild no longer needs the .metagen file to speed up the build and won't create it anymore.
The following image shows the setting in VS2010.

Related

TwinCAT Is there a difference when building a project in release or debug mode?

I've always wondered if there is a difference if you build a PLC project in the Debug or Release configuration. I don't think there is since the .compileinfo file in the _CompileInfo folder is the same size and it has the same filename (some hash I guess). Also when I log in after building with the other configuration, I do not get the prompt if I want to log in with online changes.
Does anyone know if the build configuration has an influence on the compiled code?
Short answer:
No, there is no change to the built code.
Long Answer:
The Build Configuration Tools that are referred to are primarily designed for implementation with general text based languages, rather than the TwinCAT layer that Beckhoff has stacked on top of Visual Studio.
Under standard languages there are a lot of properties that can be managed at the project level, and these properties are what are being modified when you change from debug to release configuration.
Twincat projects however are made up of two separate projects (proj_a.tsproj, proj_a.plcproj), and Visual Studio only recognizes one of these as a project file that can be modified, the .tsproj.
So if you want to see what properties will be modified by swapping between debug and release, have a look at what properties are available from the .tsproj file.
If you want to test this yourself you can disable a project file (proj_a.tsproj) and swap between debug/release to see the disabled status change as a result of swapping between the two build configurations.

How do I stop Visual Studio from building dependencies that have not changed?

The title is fairly straightforward. If I hit the build button, it acts like the "Rebuild All" button. If I have two projects, lets call them PARENT and CHILD, and I make a change to Parent and click the "Build" button. The default behavior in VS is to rebuild PARENT AND CHILD, when it should only rebuild PARENT.
I was wondering if this is an option in Visual Studio and how I can change it.
Thanks.
There seems to be some inconsistencies in your question, so I'm going to define the terms I'm using, for clarity.
Build: Compile & link everything required for the application/project
Clean: Delete all files produced as part of a build.
Rebuild: Perform a clean, then a build.
My Visual Studio doesn't have a '(Re)build All' button, it does however have a '(Re)build Solution' button, so I'm going to assume you mean that. I'm also going to assume that where you've said rebuild PARENT and CHILD, you meant build PARENT and CHILD, and that it's not recompiling each and every file in the project.
The Build and Build Solution options are not the same.
Performing a Build will evaluate the current project (and its dependencies), compiling anything required.
Performing a Build Solution will evaluate all projects in the solution, compiling anything required.
So, if you have a solution with 3 projects:
Child
Service (Dependent on Child)
FrontEnd
Then, assuming the currently selected project is Service:
Build: Would evaluate/compile: Child & Service
Build Solution: Would evaluate/compile: Child, Service & FrontEnd
Now, I believe what you are seeing is that when you perform a build on Parent, VS is performing a build on Child as well, even though it hasn't changed. I would expect that it is evaluating Child, because it needs to know if it has changed. Without performing the evaluation, there's no way it can know, which is why in your output window you'll see that it has done something with the Child project. This is usually fairly quick, although it does add up if you have a lot of dependencies.
If you don't want VS to evaluate your dependencies when you build the parent, then there are approaches you can follow but you're choosing to step away from the tools protection so unless you're careful you may get binary mismatches etc...
Some options:
Unload child projects that you're not changing (right click in solution explorer and select unload). This hides the dependency so it doesn't get compiled).
Stop letting visual studio manage your dependencies. The safest way to do this is to remove the Project Based references and instead use Binary Based references (point at the compiled output from each dependency). But this can be a non-trivial undertaking, since you have to manage your project builds yourself.
I'd suggest you think twice about what it is you're asking and evaluate whether or not the time saving (there can be some) is worth the risk that now and again you might not build everything you needed to and so end up spending time chasing your tail.
Right click on the Solution from Solution Explorer, choose Properties.
From Configuration Properties > Configuration you could exclude particular project from the build process
From Common Properties > Project Dependansies you could create and remove project dependencies
Hope this helps...
Muse Extensions
I had a similar issue with about 40 projects in one solution. For me, the following setup felt a lot less hazardous than the other answers.
In Visual Studio, open up the Configuration Manager from the Build menu.
Select <New...> from the Active solution configuration drop down.
Enter a Name (e.g. Debug Interface) and either copy settings or create an empty configuration. You should be safe to deselect Also create new project configuration(s), especially if you only want to reduce the build time.
Select or deselect the projects you want to build with your new configuration and then close the Configuration Manager.
Enjoy the shorter build time using Ctrl + Shift + B or by just building the parent project. But don't forget to change to another build configuration if you want all projects to build again. Other projects that you've deselected can still be built if you right-click on them and select Build.
More information about the Configuration Manager can be found on MSDN: Configuration Manager Dialog Box.
Please review this article:
http://blogs.msdn.com/b/kirillosenkov/archive/2014/08/04/how-to-investigate-rebuilding-in-visual-studio-when-nothing-has-changed.aspx
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\General]
"U2DCheckVerbosity"=dword:00000001
When setting the registry key (I had to add it), just use the visual studio version that's applicable to you. E.g. 14.0 == VS2015
The diagnostic that's presented can help you determine why msbuild thinks things are out of date.
I also had this problem with C++. Dependent projects would completely recompile even when I did not change their source code or header files.
I turned off "Whole Program Optimization" for all of the dependent projects. Now my projects only rebuild if I change the source code. This option for C++ projects can be found in Properties->Configuration Properties->General.
Good Luck
I have just seen a situation like that in a solution with a couple of hundred projects. Whenever you clicked "build", VS would go and rebuild most of the projects, even if you just made a full build a second ago. Same problem if you only wanted to build a single project.
It turned out the problem was a circular dependency between projects.
Normally VS does not let you create a reference from one project to another if this would cause a loop.
This only concerns "Project references", however. VS does not prevent you from adding, say ../Debug/bin/OtherSubProject.dll as a DLL reference.
Now suppose we have a solution with 100 projects, most of them, say, dependent on CoreLibrary.dll. Suppose someone adds a reference from CoreLibrary.dll to ProjectX.dll (ignoring the fact that ProjectX already depends on CoreLibrary).
If we run the build now, then first CoreLibrary.dll is built, then ProjectX.dll and all other projects.
Now suppose we run the build again, without changing anything. VS sees that one of the dependencies of CoreLibrary.dll, namely ProjectX.dll is newer than CoreLibrary.dll, and hence CoreLibrary.dll needs to be rebuilt. But of course, rebuilding the core library forces the rebuilding of all other projects, including ProjectX.dll (which will again be newer than CoreLibrary.dll).
The way to resolve this problem is to get rid of all the circular dependencies which, in particular, means that you should not reference your other subprojects via DLL references. A temporary solution while you do it would be to go to Solution Properties -> Configuration and simply disable building for one of the projects in the loop (either CoreLibrary.dll or ProjectX.dll in the example above).
There is another common reason why VS may rebuild projects which were not changed: static files with "Copy to output directory: Always" set in their properties. Avoid those.
Finally, to debug all that and figure out what is causing the rebuilds, go to Tools->Options->Projects and Solutions->Build and Run, and enable "Diagnostic" output for MSBuild. Then search for the words "not up to date" in the output window while the solution builds.
Alt + B, U will build just your current project. Good shortcut if you don't want build all projects in solution.

Visual Studio - How to refrain from compiling all project files every build?

Each time I build my Visual C++ solution in Visual Studio 2010, the entire project (not the entire solution) recompiles.
There must be a flag or configuration somewhere to make VS compile only the changed files + depending files. Where is it?
UPDATES:
I set "Yes (/Gm)" to My project's configuration properties\C/C++\Code Generation\Enable Minimal Rebuild. It still compiles all the project's files upon F7.
If in addition you get the a message similar to:
Creating ".\Release\SomeLib.unsuccessfulbuild" because "AlwaysCreate" was specified.
when building, the reason might be that one of your projects refers to a header file which does not exist on disk (see here and here).
The first link also includes a small C# script to check for this situation. To fix, simply remove the reference to the non-existing header files from your project.
Update
It might be possible that you have your precompiled-headers setting on 'Create'. To fix, right-click your project in the solution browser and select: properties -> C/C++ -> Precompiled Headers -> Precompiled Header. Change the setting from Create to Use or Not Using Precompiled Headers.
VS should behave like you want it to by default; it sounds like something is flaky going on. Clean the project, and delete your settings files (e.g. .suo / vcproj..user / etc). There are several reasons for this, some of which I've seen are:
corrupt settings files
system date/time / time zone changes confusing vc
permissions issues on the source files
The post of tul was push forward for us, because we also have had some projects, which always did re-compile. As result I have found that:
yes, option 'Minimal Rebuild' somehow was corrupted in our visual 2010 projects. I guess, this could happens when they was transformed from visual 2005.
sign of "corruption" in a particular project is that this option is assigned, i.e. it is in bold. This could be only for some configurations, e.g. Release, or for some architectures, e.g. x64. It could be in bold "NO", but still recompiles.
FIX is as easy as the next steps:
select one or even few projects in solution
right click on project -> Properties
choose Configurations: "All Configurations"
choose Platform: "All Platforms" (if you have both x32/x64)
Expand C++ group
Goto "Code Generation"
note option "Enable Minimal Rebuild" -- most probably it will be empty, because different projects/configurations have different values
set this option to NO
click button Apply
again set this option to "inherited from parent"
click button Apply. NO you should see that this option becomes "NO" but in plain text.
DONE. No need even to recompile. The next build will be much faster.
So, I was having the same problem with one of our projects. First, I was able to debug the compiler output by selecting:
-> Tools -> Options -> Projects and Solutions -> Build and Run -> MSBuild project build output verbosity -> Detailed.
It turned out that someone had set the project to always create precompiled headers for all files (/Yc). I changed the option as listed below.
-> Configuration Properties -> Precompiled Header -> Use (/Yu)
Then I set the same option for stdafx.cpp to (/Yc). So compilation of the stdafx.cpp creates the precompiled header, and all the other .cpp files use the precompiled header. This is the default scenario, and I'm not sure how it had changed for out project.
Additionally, I have changed all our compiler settings to be consistent across all projects, including:
1) Setting: C/C++ -> Precompiled Headers -> Precompiled Header -> Use (/Yu)
Switch: /Yu
Reason: Faster build time.
2) Setting: C/C++ -> General -> Debug Information Format -> Program Database for Edit and Continue
Switch: /ZI
Reason: Enables edit-and-continue, thereby improving debugging capability.
3) Setting: C/C++ -> Code Generation -> Enable Minimal Rebuild -> Yes
Switch: /Gm
Reason: Allow and speed up incremental builds and this is required for /ZI.
Hope that helps. I spent a lot of time messing with our project build settings and reading posts to Stack Overflow, and in the end, I miss C#.
I had the same issue, except mine started without reason, without me making any project configuration changes.
I would edit one file, hit build, and it would rebuild the entire project.
After much painstaking experimentation, I found that turning OFF 'Minimal Rebuild' made the problem go away. With that off, I could once more change a file and it would only compile that one file.
The weird thing was, once I had successfully made a build with minimal rebuild disabled, I could turn it back on, and everything was back to normal.
Makes me think that some cache file somewhere had become corrupted perhaps? I had tried deleting all my intermediary directories without joy, so if it was a corrupt file I don't think it was anywhere within my project directories.
Hope this helps.

Why is Visual Studio 2008 always rebuilding my whole project?

I have a Visual Studio project with about 60 C++ source files. I can do a build, and it completes without errors. But if I immediately hit F7 again, it always re-compiles about 50 of the source files. It doesn't re-compile all of the files, which is strange.
I have 'Enable minimal rebuild' (/Gm) set. Any ideas why it might be doing this?
None of the files have a Modified Date in the future.
Are any of your file dates in the future? This can occur if you changed time zones or changed the system clock time. Dates in the future will confuse the IDE and force a rebuild every time F7 or F5 is hit.
I've solved the same problem.
In my case compiler displayed warning, that /Zi option is required if /Gm is specified.
/Gm enables "minimum rebuild", which requires debug information in .pdb file. So, if you don't want to use .pdb, also disable minumum rebuild - it solved a problem in my case.
Most probably is a matter of dependencies.
Consider the following possibilities:
If you have custom build tools defined for some of the files in your solution, make sure that the output property contains the right file name(s). If the output of the build tool doesn't correspond to the one(s) specified in the output file names, the builder will rebuild that file.
If you have custom build events, check whether the output from those build events don't affect the dependencies of the files to be built.
I had problems when trying, at post-build, to copy or move some of the output files to a build folder. The post build operations that affect the timestamp of the ouput files of the build process will determine rebuild each time.
In my case of such effect (C++ via VS2005) it was on Release configuration only, and the Studio tells in the build output, that compiler option /Gm is ignored if /Zi - option is not set. After setting /Zi via
Configuration Properties -> C/C++ -> General -> Debug Information Format : Program Database (/Zi) ,
it was ok. But isn`t there something wrong, when the Release Configuration needs something about Debugging? Not yet clear to me!
Project Properties -> "C/C++" -> "Output Files" -> "Program Database File Name" option should not be empty. Set this option by selecting from drop-down box . The option will be set like this: $(IntDir)\vc90.pdb. And line ProgramDataBaseFileName="" will be removed from vcproj file.
Then only changed *.cpp files will be recompiled when you build the project or solution.
It seems that this problem can be caused by many things, but what fixed it for me was:
Closing Visual Studio
Manually deleting all bin and obj folders (Clean doesn't seem to do the trick)
Opening the solution and running Clean (I'm not sure if this is necessary, but I did it just in case...)
Building like normal
Note: This was for a C# program in Visual Studio 2010.
After a couple days of googling, I ended up with a solution to my problem.
I encountered this problem when I moved my projects to a new PC. I had checked several times the creation date of the files. These dates were up-to-date, however the modification dates were in the bast (kinda bizarre) even when I changed the files.
A simple update of the files resolved the problem.
I'm having the same problem, and it seems to be because I've turned browse information off. Properties->C/C++->Browse Info->Enable Browse Info->None. The only fix I've found is turning it back on. This is for an xbox 360 project, fwiw, my other projects don't have the problem.
A reason is if the 'date last modified' for one of the source file is set for some date in the future: it rebuilds, and then the source file is still later than the executable.
This problem with the dates can happen if the source file is located in a directory a remote machine (a network share), and/or may even happen if your machine's time isn't synchronised with the date of the machine which is running the server of your source version control system.
Check your project includes any .h header file that doesn't exist on disk. Always happens to me when I delete a header file I'm not actually including anywhere, but forget to delete it from my solution navigator in VS. Note: missing headers produce no errors during the build (when not #included anywhere).
Check your project's Program Database Filename setting. For some reason, if this is set to the name of a directory (such as "$(IntDir)\"), it can sometimes cause VS to rebuild your project every time, even if you're not generating PDB files (i.e. Debug Information Format is set to "Disabled").
This is a bug in VS2008; I have not yet reproduced it yet in VS2010, but my tests haven't been thorough, so I'm not confident saying that the behavior isn't present in VS2010.
What caused similar symptoms at me was:
I have several projects in a solution. There were .cpp files which were referenced (and therefore compiled) by >1 projects. Unfortunately Visual Studio creates .obj files with a very simple naming - it just replaces ".cpp" by ".obj". Creating wrapper .cpp-s with different named solved the problem.
I had something similar. Even though I did have pre and post build events, they weren't causing the issue. It turned out that I had a number of projects down the reference chain that had content files that were marked as "copy always" instead of "copy if newer" meaning that these projects were always considered "out of date". By changing all of these to "copy if newer", changes to my unit test project no longer forced a recompile of all of the other projects.
Disabling "minimal rebuild" (Configuration Properties > C/C++ > Code Generation) fixed it for me. The compiler even left a clue:
1>cl : Command line warning D9007 : '/Gm' requires '/Zi or /ZI'; option ignored
Although I must point out, the compiler did not ignore the option as it said.
In my case I changed system data time to previous date so it is rebuilding every time because of different time stamp of the files once changed to the current time its not rebuilding every time.
We have that here regularly:
delete all intermediate and output files by hand. The clean option in vstudio is sometimes not enough. From a fresh start do the complete build. If after a complete build vstudio still wants to recompile certain files it might be related to next bullet.
if in your vcxproj a header file is referenced which is not on disk, the project is also recompiled. You might check this by some hidden feature described on MSDN blogs or just touch (i.e. click on it to open) all header files in the project exploder and see if one does not exist on disk
Had the same problem. Solved by:
-delete output folder (obj,exe,all files)
-run cygwin
-cd project folder
-run "touch *", which reset file modify date/time
-build and enjoy problem fixed
There is similar issue with project rebuild.
Visual Studio does not recompile but re-links a project every time on F7 hit.
Fix is simple. Try to open in Editor all files included into project (from Solution Explorer double click on each file) and remove from solution those files which do not exist.

Visual Studio 2008 Unnecessary Project Building

I have a C# project which includes one exe and 11 library files. The exe references all the libraries, and lib1 may reference lib2, lib3, lib4, etc.
If I make a change to a class in lib1 and built the solution, I assumed that only lib1 and the exe would need to be changed. However, all dll's and the exe are being built if I want to run the solution.
Is there a way that I can stop the dependencies from being built if they have not been changed?
Is the key this phrase? "However, all dll's and the exe are being built if I want to run the solution"
Visual Studio will always try to build everything when you run a single project, even if that project doesn't depend on everything. This choice can be changed, however. Go to Tools|Options|Projects and Solutions|Build and Run and check the box "Only build startup projects and dependencies on Run". Then when you hit F5, VS will only build your startup project and the DLLs it depends on.
I just "fixed" the same problem with my VS project. Visual Studio did always a rebuild, even if didn't change anything. My Solution: One cs-File had a future timestamp (Year 2015, this was my fault). I opened the file, saved it and my problem was solved!!!
I am not sure if there is a way to avoid dependencies from being built. You can find some info here like setting copylocal to false and putting the dlls in a common directory.
Optimizing Visual Studio solution build - where to put DLL files?
We had a similar problem at work. In post-build events we were manually embedding manifests into the outputs in the bin directory. Visual Studio was copying project references from the obj dir (which weren't modified). The timestamp difference triggered unnecessary rebuilds.
If your post-build events modify project outputs then either modify the outputs in the bin and obj dir OR copy the modified outputs in the bin dir on top of those in the obj dir.
You can uncheck the build option for specified projects in your Solution configuration:
(source: microsoft.com)
You can can create your own solution configurations to build specific project configurations...
(source: microsoft.com)
We actually had this problem on my current project, in our scenario even running unit tests (without any code changes) was causing a recompile. Check your build configuration's "Platform".
If you are using "Any CPU" then for some reason it rebuilds all projects regardless of changes. Try using processor specific builds, i.e. x86 or x64 (use the platform which is specific to the machine architecture of your machine). Worked for us for x86 builds.
(source: episerver.com)
Now, after I say this, some propeller-head is going to come along and contradict me, but there is no way to do what you want to do from Visual Studio. There is a way of doing it outside of VS, but first, I have a question:
Why on earth would you want to do this? Maybe you're trying to save CPU cycles, or save compile time, but if you do what you're suggesting you will suddenly find yourself in a marvelous position to shoot yourself in the foot. If you have a library 1 that depends upon library 2, and only library 2 changes, you may think you're OK to only build the changed library, but one of these days you are going to make a change to library 2 that will break library 1, and without a build of library 2 you will not catch it in the compilation. So in my humble opinion, DON'T DO IT.
The reason this won't work in VS2005 and 2008 is because VS uses MSBuild. MSBuild runs against project files, and it will examine the project's references and build all referenced projects first, if their source has changed, before building the target project. You can test this yourself by running MSBuild from the command line against one project that has not changed but with a referenced project that has changed. Example:
msbuild ClassLibrary4.csproj
where ClassLibrary4 has not changed, but it references ClassLibrary5, which has changed. MSBuild will build lib 5 first, before it builds 4, even though you didn't mention 5.
The only way to get around all these failsafes is to use the compiler directly instead of going through MSBuild. Ugly, ugly, but that's it. You will basically be reduced to re-implementing MSBuild in some form in order to do what you want to do.
It isn't worth it.
Check out the following site for more detailed information on when a project is built as well as the differences between build and rebuild.
I had this problem too, and noticed these warning messages when building on Windows 7 x64, VS2008 SP1:
cl : Command line warning D9038 : /ZI is not supported on this platform; enabling /Zi instead
cl : Command line warning D9007 : '/Gm' requires '/Zi'; option ignored
I changed my project properties to:
C/C++ -> General -> Debug Information Format = /Zi
C/C++ -> Code Generation -> Enable Minimal Build = No
After rebuilding I switched them both back and dependencies work fine again. But prior to that no amount of cleaning, rebuilding, or completely deleting the output directory would fix it.
I don't think there's away for you to do it out of the box in VS. You need this add-in
http://workspacewhiz.com/
It's not free but you can evaluate it before you buy.
Yes, exclude the non-changing bits from the solution. I say this with a caveat, as you can compile in a way where a change in build number for the changed lib can cause the non built pieces to break. This should not be the case, as long as you do not break interface, but it is quite common because most devs do not understand interface in the .NET world. It comes from not having to write IDL. :-)
As for X projcts in a solution, NO, you can't stop them from building, as the system sees a dependency has changed.
BTW, you should look at your project and figure out why your UI project (assume it is UI) references the same library as everything else. A good Dependency Model will show the class(es) that should be broken out as data objects or domain objects (I have made an assumption that the common dependency is some sort of data object or domain object, of course, but that is quite common). If the common dependency is not a domain/data object, then I would rethink my architecture in most cases. In general, you should be able to create a path from UI to data without common dependencies other than non-behavioral objects.
Not sure of an awesome way to handle this, but in the past if I had a project or two that kept getting rebuilt, and assuming I wouldn't be working in them, I would turn the build process off for them.
Right click on the sln, select configuration manager and uncheck the check boxes. Not perfect, but works when Visual Studio isn't behaving.
If you continue to experience this problem, it may be due to a missing or out of date calculated dependency (like a header) that is listed in your project, but does not exist.
This happens to me especially common after migrating to a new version (for example: from 2012 to 2013) because VS may have recalculated dependencies in the conversion, or you are migrating to a new location.
A quick check is to double-click every file in offending project from solution explorer. If you discover a file does not exist, that is your problem.
Failing a simple missing file: You may have a more complicated build date relationship between source and target. You can use a utility to find out what front-end test is triggering the build. To get that information you can enable verbose CPS logging. See: Andrew Arnott - Enable C++ and Javascript project system tracing (http://blogs.msdn.com/b/vsproject/archive/2009/07/21/enable-c-project-system-logging.aspx). I use the DebugView option. Invaluable tool when you need it.
(this is a C# specific question, but a different post was merged as identical)

Resources