Debugger multiple environment variables in C++ Microsoft Visual Studio 2010 - c++

I got a very simple problem with the Visual Studio 2010 Professional C++ debugger when setting environment variables.
Described in
http://msdn.microsoft.com/en-en/library/kcw4dzyf.aspx
Paragraph "Environment (Local Windows Debugger)".
I created a standard Win32 console project. I am setting the environment in project properties → Debugger:
TEST=asdf
OTHER=qwer
And printing the environment variables in the _tmain(...):
cout << "Hello " << getenv("TEST") << endl;
I would expect an out like:
"Hello asdf"
But instead I always get:
"Hello asdf OTHER=qwer"
How to fix this?!
It seems to be a DEU version bug.
I just filed a bug report:
https://connect.microsoft.com/VisualStudio/feedback/details/727324/msvs10-c-deu-debugger-environment-variables-missing-linefeed#details

Running into a similar problem feeding this property programmatically, I bumped into this github file. The separator is "
" in xml format, a.k.a. line feed. Using Environment.Newline solved the issue in dot net.
In interactive mode within the GUI, you want to click the edit button and use the rerun key to split your variables.

Best solution so far:
Considering your example:
TEST=asdf
OTHER=qwer
Edit the .vcxproj adding inside <Project>:
<Project .... >
...
<PropertyGroup Label="UserMacros">
<TEST>asdf</TEST>
<OTHER>qwer</OTHER>
</PropertyGroup>
...
</Project>
You can also add this on a *.vcxproj.user or a *.props file as you prefer.

Do you need to separate the environment variables with semicolons or some other kind of delimiter? It seems like TEST is getting assigned to asdf OTHER=qwer, not just asdf.

Related

Why doesn't the c++ file run in visual studio

So I tried making a basic game on the console using screen buffers, I was able to create it and make a square move in the canvas, but for my next project I looked up a website with the ASCII characters and pasted a couple into a comment at the end of the c++ file, when I ran the file visual studio prompted:
I clicked yes and it didn't run anymore.
Also I recently have installed an extension for visual studio (before it didn't run, the extension works fine but I don't know if the extension may have caused this as I didn't tried running it with the extension downloaded and applied), when I open visual studio and open a file it says:
The last record in the ActivityLog xml file, has a type of error and it's description is:
Microsoft.VisualStudio.Composition.CompositionFailedException: Expected 1 export(s) with contract name "Microsoft.VisualStudio.CppSvc.Internal.CodeAnalysis.ICodeAnalysisService" but found 0 after applying applicable constraints.
at Microsoft.VisualStudio.Composition.ExportProvider.GetExports(ImportDefinition importDefinition)
at Microsoft.VisualStudio.Composition.ExportProvider.GetExports[T,TMetadataView](String contractName, ImportCardinality cardinality)
at
Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T,TMetadataView](String contractName)
at
Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T](String contractName)
at
Microsoft.VisualStudio.Composition.ExportProvider.GetExportT
at
Microsoft.VisualStudio.Composition.ExportProvider.GetExportedValueT
at Microsoft.VisualStudio.ComponentModelHost.ComponentModel.GetServiceT
at Microsoft.VisualStudio.VC.ManagedInterop.<>c.<Initialize>b__52_15()
at
System.Lazy`1.CreateValue()
at
System.Lazy`1.LazyInitValue()
at
System.Lazy`1.get_Value()
at
Microsoft.VisualStudio.VC.CodeAnalysis.ResultTaggerProvider.CreateTagger[T](ITextBuffer buffer)
at
Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator`1.GatherTaggers(ITextBuffer textBuffer)
--- End of stack trace from previous location where exception was thrown ---
at
Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
I have Visual Studio 2017
So why does running the file (with the local windows debugger button) say that there were build errors? And how can I fix it?
When it prompts the build error, and I click no it usually shows the errors but in this case it doesn't, yes will just run the last "successful" build (although I haven't changed the file since I have finished it before this error message started popping up)
Also there is no error in my code as I was able to run it before the build error kept appearing and I haven't touched the file since(only now to show the problems are)
Thanks for your time! if anything was unclear because of my English, comment and I'll try to clarify it
I fixed the error by deleting ComponentModelChache folder located at:
C:\Users\%userName%\AppData\Local\Microsoft\VisualStudio\15.0
15.0 is the version of your visual studio so it varies depending on the version you're using, %userName% is a replacement for the user you're logged in as

How to stop Visual Studio 2017 from randomly switching projects to run in IIS Express when they're configured to run in Local IIS?

Our team recently upgraded to Visual Studio 2017. We store our server settings in the project file to use Local IIS, but opening up the properties of the project shows it to be using IIS Express. This occurs seemingly at random and has been affecting random teammates ever since we upgraded.
The .csproj file in source control shows the following:
<PropertyGroup>
...
<UseIISExpress>false</UseIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<Use64BitIISExpress />
...
</PropertyGroup>
as well as:
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{...}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>53703</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost/MyProject</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
When this occurs, it seems to randomly set <UseIIS>True</UseIIS> to False and teammates are accidentally checking in this change when they don't catch it. Is there a way to stop this from happening?
I was told by Microsoft support that this is a known issue with Visual Studio 15.6:
Bill Hiebert [MSFT] · Mar 21 at 10:11 PM 1
Apologies for the delayed response, but we have identified the issue
and are working on a fix. The problem manifests itself if the
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
section is missing from the .user file which can happen more easily in
15.6.
https://developercommunity.visualstudio.com/content/problem/208768/vs-156-does-not-respect-the-apply-server-settings.html
Turns out some team members haven't patched up their Visual Studio to latest yet.
Edit the file .csproj.user of the project and disable IIS Express:
<UseIISExpress>false</UseIISExpress>

How could I remove "error C4335: Mac file format detected" in VC 2008

I am now compiling a project with VC++ 2008, and the error I have obtained is as follows:
Error 7 error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
I was wondering how I could solve this kind of errors. I have found this link useful but the solution is suitable for VC++ 2010 rather than VC++ 2008. Any suggestion will be appreciated.
For VS2012 select and open the file within solution explorer. File->Advanced Save Options-> Set Encoding: Western European (Windows) && Set Line endings: Unix
You can use this addon to make the conversions automatically across your project, it's extremely easy.
Just save it in the format you want; VC+ 2008: http://msdn.microsoft.com/en-us/library/aad7fash(v=vs.90).aspx
You can open your file with Sublime Text, then open "View"->"Line Endings"->Unix/Windows. Then save the file.
Mac formatted files contain \r at the end of each line and that can cause in some cases compilation errors. Just remove the \r in each end of line and only use '\n' and try again. This warning should be then gone.
See also https://www.oreilly.com/library/view/mac-os-x/0596004605/ch01s06.html

How to launch the associated application for a file / directory / URL?

Linux seems to be easy: xdg-open <file/directory/URL>.
Apparently, Mac is similar: open should be used instead of xdg-open. I don't have access to a Mac so I couldn't test it.
For Windows, I found 4 different suggestions and those that I have tried failed.
Is there a non-java, cross platform way to launch the associated application for a certain file type?
suggests start
How to give focus to default program of shell-opened file, from Java? suggests
cmd /c start ...
How to open user system preferred editor for given file?
How to Find Out Default File Opener with Java?
suggest RUNDLL32.exe
What is the correct way to use ShellExecute() in C to open a .txt
Open file with Windows' native program within C++ code
How to use ShellExecute to open html files in Windows using C++? suggest
ShellExecute
I have tried the first 3 with system() and QProcess::startDetached() and "http://www.stackoverflow.com" as argument but they all failed; start works just fine from the command line though. I haven't tried ShellExecute yet.
What is the Windows equivalent of xdg-open? It seem to me, it is start but why did my attempts with start fail?
Is ShellExecute my only option?
EDIT I thought QDesktopServices::openUrl() was for web pages only because it did not work for files or directories.
After some debugging I figured out that if I replace \\ with / in the path on Windows, it works for files but the directories are still not opened. Any ideas what I am doing wrong?
QDir dir("C:/Documents and Settings/ali");
qDebug() << "Exists? " << dir.exists();
qDebug() << dir.absolutePath();
QDesktopServices::openUrl(QUrl(dir.absolutePath()));
qDebug() << "External app called";
Application Output:
Exists? true
"C:/Documents and Settings/ali"
External app called
But nothing happens, the directory is not opened. On Linux, directories are opened with the default file manager as expected.
SOLUTION: Due to the Qt bug and Windows quirks (malformed application window), I ended up using ShellExecute. That gives me enough flexibility to achieve exactly what I want at some expense...
Why don't you just use Qt's support for this? For example:
QDesktopServices::openUrl(QUrl("/home/realnc/test.pdf"));
This opens the document in Acrobat Reader. In general, it obeys the preferred application settings in my OS for all file types that have one or more applications associated with them. Best of all, it's platform-independent.
Edit:
The fact that it opens directories on Linux but not on Windows smells like a bug. It might be best to report this on Qt's bug tracker. In the meantime, you could have a workaround for Windows for when the file is a directory:
#ifdef Q_WS_WIN
if (QFileInfo(path).isDir())
QProcess::startDetached("explorer", QStringList(path));
else
#endif
QDesktopServices::openUrl(QUrl(path));
You can also do it with cmd.exe's start command, but you'll get an ugly terminal pop up for a few fractions of a second:
QProcess::startDetached("cmd", QStringList() << "/C" << "start"
<< QDir::toNativeSeparators(path));

visual studio 2010 issue

When I write a program using C++ and I want to run it, I can't catch the console window. I press CTRLF5 and it does not work.
I want the window to stay open and wait, even it finishes executing. Can anyone help me?
Thanks in advance.
http://connect.microsoft.com/VisualStudio/feedback/details/540969/missing-press-any-key-to-continue-when-lauching-with-ctrl-f5
In the older versions it would default to the console subsystem even if you selected "empty project", but not in 2010, so you have to set it manually. To do this select the project in the solution explorer on the right or left (probably is already selected so you don't have to worry about this). Then select "project" from the menu bar drop down menus, then select "*project_name* properties" > "configuration properties" > "linker" > "system" and set the first property, the drop down "subsystem" property to "console (/SUBSYSTEM:CONSOLE)". The console window should now stay open after execution as usual.
try using system("Pause"); as the last line on your code (before the return of your main function)
Ctrl+F5 should work. Just in case, if you have the source of your program, add the following just before the closing brace of main.
int x;
cin >> x;
the program will wait for you to enter some value.
If you want a breakpoint to be triggerred in debugger, do simple F5 instead of Ctrl+F5, after putting a breakpoint on the relevant source line (assuming the source/debug symbols are available)
Sorry to say, Ruba, but it looks like Microsoft removed this nifty little feature when moving from VS2008 to VS2010.
I can't find anything on MSDN, the web in general, or VS options to turn it back on.
My advice is to bypass the environment altogether for testing your application. Simply open a cmd.exe window in your runtime directory (debug or release or whatever), build the executable within the IDE then switch to the command window and enter testprog.exe to run your program.
Make sure you include any required command line parameters and, after you've entered it the first time, you can just use the up-arrow to retrieve the last command.
Yes, it's a bit of a pain but, until someone comes up with a better solution, it's probably the best way to ensure you see all the output while ensuring the program has shut down completely.
Just set a breakpoint at main()'s closing curly brace if you want to see the console after the program is finished.
You should create VS 2010 C++ Projects as below:
New project -> Visual C++ -> Win32 -> Win32ConsoleApplication
In this way you will be getting "Press any key to continue..." when you run program with ctrl+F5, as it was in VS 2008.
EDIT :
New project -> Visual C++ -> Win32 -> Win32ConsoleApplication -> Next -> Check 'Empty project' -> Finish = what you actually need.