error MSB4018: The “VCMessage” task failed unexpectedly' in Visual Studio 2017 - visual-studio-2017

Visual Studio 2017 Professional.
Native C++ project.
After I have changed some of project settings project building ends with this:
Microsoft.CppCommon.targets(770,5): error MSB4018: The "VCMessage" task failed unexpectedly.
Microsoft.CppCommon.targets(770,5): error MSB4018: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Microsoft.CppCommon.targets(770,5): error MSB4018: at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
...
PlatformToolSet mentioned here is set.
What's wrong?

This time it is
Configuration Properties -> Linker -> Debugging -> Generate Program Database File
If the file name is omitted (while the neighbour option "Generate Debug Info" is not "No") then VS-2017 finishes building with the error MSB4018. A target is built in this case nevertheless.

Right-click on the project and go to Properties > Linker > General.
Then set "Output File" to "Inherit from parent or project defaults"

Go to the error list window and click on the error and you may get more information. In my case it pointed to a line in Microsoft.CppCommon.targets which was an XML element. In the arguments attribute one value was %(Link.ProgramDatabaseFile) which was not set and causing the problem.

Related

.NET Core MSTests fail because of "Illegal characters in path"

When I click Run All .NET Core tests (the MSTest version) they do not run. It fails saying in the bottom left corner "Unexpected error detected. Check the Tests Output Pane for details".
I checked the output and this is the error:
[4/8/2018 19:29:53 Informational] ------ Run test started ------
[4/8/2018 19:29:53 Error] System.ArgumentException: Illegal characters in path.
I created a blank project called "Thing.Tests". The path is
C:\Users\james\OneDrive\Documents\visual studio
2017\Projects\Thing.Tests\Thing.Tests\Thing.Tests.csproj
What the issue is??
Check out your system PATH:
echo %PATH%
I ended up having an entry with double quotes (which Visual Studio didn't like very much). Once I deleted that entry it worked like a charm.
You can edit it through the Environment Variables
Control Panel > System > Advanced System Settings > Environment Variables

Visual Studio 2015: C++ code analysis error C1253, unable to load model file 'res://mspft140.dll/300'

Visual Studio 2015 Community update 3, trying the C++ code analysis feature. The settings are as follows:
solution properties > code analysis settings > [all configurations] [all platforms] : microsoft native recommended settings
project properties > code analysis > [all configurations] [all platforms] : microsoft native recommended settings
Whenever I run analyze > run code analysis on solution I would always get a c1xx : fatal error C1253: Unable to load model file 'res://mspft140.dll/300'. This happens to every project, new or existing. MSDN is not particularly helpful about this one.
The string is a res protocol, so I checked if the dll mentioned is at its correct location (there are two actually, at c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\ and c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64), and opened them with resedit. Both contain an XML resource named 300, so I don't see any reason for VS being unable to load it. Resetting the settings didn't help, full uninstall and reinstall (half a day wasted) did neither.
I also ran procmon with [Path] [contains] [mspft] filter while running the code analysis in VS, but the file system results are only SUCCESS and FILE LOCKED WITH ONLY READERS, which seems to be ok.
Did anyone experience this error? Does anyone have any surmises about its cause?
Update: After looking thoroughly through many more procmon captures with different filters I found out that cl.exe tries to open this registry key value: HKCR\PROTOCOLS\Handler\res\CLSID. Clearly it looks for the handler of the res protocol mentioned in the error output - and it's not there to be found, while many siblings of res key refer to some valid handlers, for example, http key has CLSID value of {79eac9e2-baf9-11ce-8c82-00aa004ba90b}. I guess that my quest for now is figuring out what that res CLSID is meant to be.
I was right in my assumption about the res protocol handler. The correct HKCR\PROTOCOLS\Handler\res\CLSID value is {3050f3bc-98b5-11cf-bb82-00aa00bdce0b} (which refers to C:\Windows\System32\mshtml.dll). For some reason my registry was missing it; as soon as I added the value, the code analysis started working without errors.
I hope this helps someone, although I believe the bug is extremely rare.

Invalid or Corrupt file after force closing Visual Stuio during build

I opened up task manager and force closed visual studio during a build. I now get an error that says invalid or corrupt file:
1>Debug\main.obj : fatal error LNK1136: invalid or corrupt file
How can i fix this?
Select "Build" -> "Rebuild Solution" in the menu. (From memory; this might be slightly wrong)
This will delete any leftover temporary files from the last build, and rebuild the solution from scratch.

Visual Studio error D8016: '/ZI' and '/O2' command-line options are incompatible

Visual Studio error D8016: '/ZI' and '/O2' command-line options are incompatible
I'm using optimization for the first time with C++.
When I 'build solution' I keep getting this error.
In the property pages, I have configuration set to Release
Under project/properties/c++/optimization I tried all the options except for disable.
Under project/properties/c++/General I also tried all the options under 'Debug Information Format' (assume 'None' is a good choice?).
I think it might have something to do with the linker settings, but still don't know what to do.
Go to the project's property page and change the value for:
C/C++ | General | Debug Information Format
To something other than "Program Database for Edit and Continue (/ZI)"
For example, "Program Database (/Zi)" should work.
After changing
C/C++ | General | Debug Information Format
to Program Database (/Zi)
You might need to set the solution configurations to Release.
Verify that under Linker -> Debugging says Generate Debug Info -> No.
I had this problem as well.

Problem while building a .dll (Visual C++)

I am trying to build a .dll in order to link it to one of my projects. But the build always fails : I got these messages in the output and I don't know what it means. It seems that something is missing, but I couldn't find what.
I am trying to link a Mesher called Netgen
http://www.hpfem.jku.at/netgen/
1>adfront2.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification
1> Creating library D:\Documents\Visual Studio 2008\Projects\converter/lib\nglib.lib and object D:\Documents\Visual Studio 2008\Projects\converter/lib\nglib.exp
1>Embedding manifest...
1>Performing Post-Build Event...
1>Environment variable NETGENDIR not found.... using default location!!!
1>POSTBUILD Script for nglib ........
1>Installing required files into XXX\Netgen\windows....\nglib-instNoOCC_Win32 ....
1>File not found - nglib.dll
1>0 File(s) copied
1>POSTBUILD Script for nglib FAILED..... Error copying the nglib DLL into install folder!!!
1>Project : error PRJ0002 : Error result 1 returned from 'C:\Windows\SysWow64\cmd.exe'.
1>Build log was saved at "file://D:\Documents\Visual Studio 2008\Projects\converter\BuildLog_nglib.htm"
1>nglib - 1 error(s), 49 warning(s)
I hope I am clear enough and thank you by advance for your help.
seems this NetGen lib's project wants to run a post-build event in which it tries to copy the main output (the nglib.dll) to the directory NETGENDIR (which is supposed to be an environment variable). This fails beccuse the dll isn't found.
Either disable the post build event, or check with the NetGen lib's creator what they expect here, there seems to be a mismatch between the project's output dir and the postbuild event.
Would also be nice to see the postbuild event from the vcproj file, maybe you can post it?
You need read, by example the output line:
1>Environment variable NETGENDIR not found.... using default location!!!
After that I suggest that you must read the documentation about how define a enviroment variable named: NETGENDIR