How to use Microsoft Visual Studio in CSIL
About Microsoft Visual Studio
Overview
"The Microsoft Visual Studio development system is a suite of development tools designed to aid software developers - whether they are novices or seasoned professionals - face complex challenges and create innovative solutions. Visual Studio's role is to improve the process of development and make the work of achieving breakthroughs easier and more satisfying." - from www.microsoft.com
We have Microsoft Visual Studio Enterprise 2017 installed on all CSIL Windows systems.
General
Where I can find Visual Studio on a CSIL system?
What is a Visual Studio project?
Where I can create standalone application by using Visual Studio?
How to I can create standalone application by using Visual Studio?
How to configure Visual Studio so it works well in CSIL?
When I logon to CSIL Windows Terminal Server, where I can create standalone application by using Visual Studio?
Start programming
How to create a C# console application?
How to create a Visual Studio web project?
How do I create a C# project to access CSIL SQL Server?
How to build an application under Visual Studio?
How to run/debug a Visual Studio project?
How to build a C++ OpenGL application under Visual Studio?
How to build a C++ OpenCV application under Visual Studio?
Solving Mysteries
Visual Basic crashes when I load my project - it worked yesterday on the same computer.
I get an "Access Denied" error when I load my project in Visual Basic, and some of the functions are missing.
I can't add new component into my Visual Basic project.
I have a Visual Studio project, but Visual Studio won't compile it.
I cannot create/open/debug Visual Studio solutions. What should I do?
When I use Visual Studio, I always get "Not enough space", or "Disk is full" error messages.
Keyboard is not working under Visual Studio! What should I do?
Visual Studio does not function as expected! What should I do?
I have difficulties to run my .NET application within a browser. What should I do?
Visual Studio failed to create project on my SFU Home! What should I do?
My Visual Studio program gets permision error! What should I do?
Visual Studio says my project is not trusted! What should I do?
Where I can find Visual Studio on a CSIL system?
The Visual Studio program only runs on Windows systems. In CSIL, all Windows workstations and the CSIL Windows Terminal Server have the Visual Studio installed.
After logon to the system, you should locate the Visual Studio by name "Visual Studio 2017".
Please note: this is the only shortcut to launch Visual Studio in CSIL.
What is a Visual Studio project?
A project some times it is also called a solution or an application. It is the repository for the basic Visual Studio infrastructure, user's codes and other resources. Based on the project's type, the compiled project could serve lots of purposes: a standalone application, a library, a web application, a smart device application, etc.
Where I can create standalone application by using Visual Studio?
Due to security concerns, Windows only runs "trusted" application. With same token, Visual Studio can only debug those "trusted" projects. So, you must create your project on a server or site in the Trusted Zone. And Windows only trusts the UNC (Universal Naming Convention) path to a remote file server.
In CSIL, we have setup the Trusted Zone to include the sphinx.sfu.ca (IT Services fileserver) and CSIL IISserver. So, any project you created on these servers is trusted.
Thus, your project's location must be like this
\\sphinx.sfu.ca\username\MyApp1
Warning:
Create your projects under \\freesia\userdata\username\... or on U: will NOT work properly.
The alternative: you may also create your project on a local hard drive (e.g. D:\). The local hard drive is always trusted by the system.
Note:
Copy your projects back to your SFU Home file space before you logoff. The user files on local hard drive may be deleted without advanced notice.
If you are using CSIL Windows Terminal Server, click here.
How to I can create standalone application by using Visual Studio?
Please create solution under this folder (or its sub-folder)
\\sphinx.sfu.ca\username\
Warning:
Create your projectsunder \\freesia\userdata\username\... or on U: will NOT work properly.
If you haven't done the configuration stated in previous Q&A, you may encounter these:
Note:
When the dialog box titled with "Found a suitable location for browseing database & IntelliSense files" shows up, please
- CHECK "Do not prompt again."
- click "Cancel"
Note:
When the dialog box titled with "Security warning for ..." shows up, please
- UN-CHECK "Ask me for every project in this solution."
- click "OK"
How to configure Visual Studio so it works well in CSIL?
Microsoft has made some changes to the Visual Studio IDE and some configurations are needed to ensure it runs well in CSIL:
Launch Visual Studio, then do the following
- click menu item Tools -> Options...
- in the dialogbox, on the left pane, navigate to Text Editor -> C/C++ -> Advanced
- on the right pane, notice the Fallback Location, there are 3 items, alter the following 2 of them:
- change Always Use Fallback Location to True
- change Fallback Location to \\sphinx.sfu.ca\username\VSProjects
- let's do another part: in the dialogbox, on the left pane, navigate to Projects and Solutions -> General
- on the right pane, notice the location settings:
- change the Project location to \\sphinx.sfu.ca\username\VSProjects
- change the User Project templates location to \\sphinx.sfu.ca\username\VSProjects\Templates\ProjectTemplates
- change the User item templates location to \\sphinx.sfu.ca\username\VSProjects\Templates\ItemTemplates
- click OK to save the settings
Note: the folders must be on sphinx.sfu.ca, the folder names could be your choice.
When I logon to CSIL Windows Terminal Server, where I can create standalone application by using Visual Studio?
Backgound: for unknown reasons, the CSIL Terminal Server would not "FullTrust" any network space.
Please locate folder D:\users\username and create your projects under this folder.
For some of the CMPT courses, there might be a different location designated for storing user files. Please follow the email sent by CSIL Administrator for details.
Note:
Copy your projects back to your SFU Home file space before you logoff. The user files on local hard drive may be deleted without advanced notice.
Start programming
How to create a C# console application
A console application is an application without a graphical user interface. Please follow these steps:
- launch Visual Studio
- select "File -> New -> Project" from the menu bar
- click "Visual C# Projects" from the left pane "Project types"
- select "Console Application" from the right pane "Templates"
- name your project
- specify the location: please make sure it is a "fully trusted" location. e.g. sphinx.sfu.ca
- click the "OK" button, Visual Studio will create your project and provide you some start-up code.
Note: This process does not create the commenting, you have to add it yourself. If you want automatic comment formatting, type three forward slashes (///). Otherwise, type two forward slashes (//) for non-automatic comments.
Warning:
Create your projects under \\freesia\userdata\username\ or on U: will NOT work properly.
How to create a Visual Studio web project
When you want to create a web project which will run on the CSIL IIS server, the location of the project will be: https://CSILIIServer.csil.sfu.ca/username???/WebApp1
Please follow these steps:
- Launch Visual Studio
- Click on the File - > New - > Web Site... menu
- select ASP.NET Web Site from top pane "Templates"
- select HTTP as the Location's type
- type https://CSILIIServer.csil.sfu.ca/username???/WebApp1 as the location
- select a language for your web application
- click OK to create the web application
How to build an application under Visual Studio?
Build the project involves compile the project and link all the necessary libraries to generate a final application.
In order to build the application, click menu item Build -> Build ConsoleApplication (if you use another name for your application, e.g., test1, it will be Build test1) from the menu bar.
A new window named "output" will show up while the application is being built. If everything goes well, a message will appear in the "output" window.
If your program has bugs, there will be a "Error List" window overlay the output window. The building errors and warnings will appear in this window. You can double-click the item to direct Visual Studio to highlight the codes in doubt.
Important tips
- Always correct the first error before trying the others. The first error is always accurate, but the later errors may be the chain effect of the first error.
- Hit F1 key to launch MSDN library to help you on the topic you select.
- Try to correct the codes which generate the warnings. Despite the building is successful, the project may still contain some codes which may generate warnings.
How to run/debug a Visual Studio project?
- For a standalone project, you can do the following:
After you corrected all the errors and the program is successfully built, you can hit F5 to start debugging your program or hit Ctrl+F5 to run your program without debugging. - For a web project, you must run/debug your web project from a browser.
Your project is will have the URL like this:
https://CSILIISServer.csil.sfu.ca/username???/WebApp1
(credential: your SFU Computing ID and password)
How to build a C++ OpenGL application under Visual Studio?
- preparation (this is already done by CSIL Administrator). Click here if you want to know the details.
- launch Visual Studio
- create an empty Visual C++ Win32 Console Application on a Full Trust location
- add a new item (a cpp file) to your project, name it as you wish
- place your codes in this new cpp file
- in the Solution Explorer pane, right click the project and select Properties , in the newly opened dialog box:
- for Configuration combo box, select All Configuration
- on the left pane, navigate to: Configuration properties -> Linker -> Input
- on the right pane, click Additional Dependencies
- place this line as the text: opengl32.lib glu32.lib glut32.lib
- click OK to save the configurations
- build and debug your program
How to build a C++ OpenCV application under Visual Studio?
For OpenCV-2.4.8 build - the one currently on CSIL Windows workstations:
- launch Visual Studio
- create an empty Visual C++ Win32 Console Application on a Full Trust location
- In the Solution Explorer window, right-click the project name and select properties
- in the newly opened dialog box (... Propertiy Pages)
- on the left pane, navigate to: Configuration Properties -> VC++ Directories
- on right pane, for Include Directories... add: C:\program files (x86)\OpenCV\build\include
- on right pane, for Library Directories... add: C:\program files (x86)\OpenCV\build\x86\vc10\lib
- on the left pane, navigate to: Configuration Properties -> Linker -> Input
- on right pane, for Aditional Dependencies..., add the following depends on the configuration (you may add more as needed):
- for Debug builds:
- opencv_core248d.lib
- opencv_highgui248d.lib
- for Release Builds:
- opencv_core248.lib
- opencv_highgui248.lib
- for Debug builds:
- click OK a few times to save the settings; now you can add your own code.
You may find more tips on OpenCV's official site, e.g. on this external page.
Note: this Q&A is still under reviewing. Please comment.
About the versions: the latest version is 2.4.8 (released on 2013.12.31).
(obsolete, for reference only) For OpenCV-2.2.0 build - which was obsolete.
- launch Visual Studio
- create an empty Visual C++ Win32 Console Application on a Full Trust location
- In the Solution Explorer window, right-click the project name and select properties
- in the newly opened dialog box (... Propertiy Pages)
- on the left pane, navigate to: Configuration Properties -> VC++ Directories
- on right pane, for Include Directories... add: C:\program files (x86)\OpenCV\include\opencv
- on right pane, for Library Directories... add: C:\program files (x86)\OpenCV\lib
- on right pane, for Source Directories... add: the following:
- C:\program files (x86)\OpenCV\src\cv
- C:\program files (x86)\OpenCV\src\cvaux
- C:\program files (x86)\OpenCV\src\cxcore
- C:\program files (x86)\OpenCV\src\highgui
- C:\program files (x86)\OpenCV\src\ml
- on the left pane, navigate to: Configuration Properties -> Linker -> Input
- on right pane, for Aditional Dependencies..., add the following depends on the configuration:
- for Debug builds:
- opencv_core220d.lib
- opencv_highgui220d.lib
- for Release Builds:
- opencv_core220.lib
- opencv_highgui220.lib
- for Debug builds:
- click OK a few times to save the settings; now you can add your own code.
Solving Mysteries
Visual Studio does not function as I expected; how to reset Visual Studio environment - aka make it work again?
Technical background:
Microsoft Visual Studio is an extremely complex integrated development environment/tool. Sometimes, Visual Studio bwhaves strangely without apparent reason. In most cases, this is because for some (unknown) reason, the user's personal environment/configurations of Visual Studio got corrupted.
The personal configurations of Visual Studio are initialized when the user launches (a specific version of) Visual Studio for the first time. The configurations are stored in two places: as part of the user profile file (ntuser.dat) and a folder under user profile's application data folder.
We noticed that most of the Visual Studio issues could be solved by simply remove the corrupted configuration folder under user profile's application data folder. This will trigger a simple initialize this portion of the configurations when the user launches (the specific version of) Visual Studio the next time.
Here are the instructions for CSIL users:
- from a CSIL Windows system, terminate all Visual Studio processes
- launch Windows Explorer
- goto the folder:
\\freesia\userdata\username\AppData\roaming\Microsoft\VisualStudio- delete this folder: 8.0
- delete this folder: 9.0
- delete this folder: 10.0
- delete this folder: 11.0
- delete this folder: 12.0
- delete this folder: 15.0
Now, launch Visual Studio again to see if it is working.
If it still does not work, please email helpdesk - we may have to reset your profile.
Visual Basic crashes when I load my project - it worked yesterday on the same computer.
When users add ActiveX control components (most of these are named with the file extension *.ocx, some with *.dll) into their VB project, VB will check the "Control Typelib Cache" file (named *.oca, associated with the *.ocx file). If this cache file doesn't exist (it should be in the same folder as the one in which the ActiveX control is located), VB will attempt to generate one. Users must have write permission on this folder in order to generate the cache, and since no students in CSIL have such access, the system will give you an "Access denied" message or just terminate the application.
When this happens, please email helpdesk.
I get an "Access Denied" error when I load my project in Visual Basic, and some of the functions are missing.
Please see here for details.
I can't add new component into my Visual Basic project.
Please see here for details.
I have a Visual Studio project, but Visual Studio won't compile it.
Please check the project settings and VC++ configuration to make sure all the directories and options are correct. Visual Studio tools behave abnormally when:
- the project folder is on your desktop.
- the project folder is part of your profile.
- the project folder is a subfolder of "My Documents" or "Documents".
- there is not enough space on the drive the project folder is located on. You need at least 6MB.
Please note: other Visual Studio tools may fail for the same reason; the solution presented here should work as well.
I cannot create/open/debug Visual Studio solutions. What should I do?
First of all, please be sure to create/open every solution on a FullTrust location.
Please read through this page for the instructions on how to make it work - this Q&A may help you reset the Visual Studio environment on your own.
If you find that the instructions are not sufficient, please Please email helpdesk for clarifications.
When I use Visual Studio, I always get "Not enough space", or "Disk is full" error messages.
When the project is set to "Debug" mode, Visual Studio will create many pre-compiled files under the "debug" folder. These files are for reducing the compiling time in the future. They are usually about 5-10MB (if you are using MFC).
If you compile your project on the scratch disk, you will never encounter this problem. Please copy all of the useful files back to your home directory before logging off.
NOTE: To protect your privacy, remove your files from scratch disk when you're done with them, otherwise other people can use them.
Keyboard is not working under Visual Studio! What should I do?
You may follow these steps to reset the environment:
- from a CSIL Windows system, terminate all Visual Studio processes
- launch Windows Explorer
- goto the folder:
\\freesia\userdata\username\AppData\roaming\Microsoft\VisualStudio- delete this folder: 8.0
- delete this folder: 9.0
- delete this folder: 10.0
- delete this folder: 11.0
- delete this folder: 12.0
- delete this folder: 15.0
For the techinical deatils, please check out this Q&A.
Visual Studio does not function as expected! What should I do?
Please follow the steps stated in this Q&A . If it does not fix the problem. Please contact helpdesk.
I have difficulties to run my .NET application within a browser. What should I do?
1. Pay close attention to the Web.Config file, it is case-sensitive (the nature of XML). You may try the following:
Find segment:
<configuration>
<system.web>
...
</system.web>
</configuration>
Insert this line to 'system.web' section:
<customErrors mode="Off" />
Comment out this line from 'system.web' section:
<authentication mode="Windows" />
2. Try to use SQL Server standard login for your database connection.
Visual Studio failed to create project on my SFU Home! What should I do?
In general, this indicates Visual Studio could not configure itself properly. The most likely cause is: there is no enough space on your CSIL Windows profile folder to store the settings.
Please check this Q&A for instructions on how to free up space. If it does not fix the problem. Please contact helpdesk.
My Visual Studio program gets permision error! What should I do?
Most likely, this is because the system does not FullTrust the location which contains your program. This is a known issue on Windows Terminal Server.
If you are using CSIL Windows Terminal Server, check this previous Q&A.
Workaround step #1:
- open the project within Visual Studio
- navigate to Solution Explorer
- double click Properties of the solution
- in the dialog box, on left pane, click Security
- check "Enable Clickonce security settings"
- check the radio button "This is a full trust application"
This should allow the project to debug without issue.
If you still experience similar issue, please follow to the next step:
Workaround step #2:
You may create/debug/run your project on the local hard drive (e.g. D:\<username>). The local hard drive is always FullTrust-ed by the system.
Just remember: Copy your project on the local hard drive back to your space on IT Services fileserver (sphinx.sfu.ca) before you logoff. The user files on local hard drive may be deleted without advanced notice.
Detailed errors (example):
A first chance exception of type 'System.Security.SecurityException' occurred in System.Data.dll
Request for the permission of type 'System.Data.SqlClientPermission, System.Data, Version=2.0.0.0, Cultlture=neutral, PublicKeyToken=b77a5c561934e089' failed
Visual Studio says my project is not trusted! What should I do?
Please click here for workaround.
Detailed errors (example):
The project lcation is not trusted:
u:\...
Running the application may result in security exceptions when it attempts to perform actions which require full trust.
Visual Studio does not debug my program and complain about "Uncaught exception thrown by method called through Reflection." What should I do?
This error occurs when the project's debug configuration is not correct. Please do the following:
on the solution explorer window, select the projector, right-click the project and select "Properties"
within the newly opened window, select the "Debug" from the left pane
on the right pane, location the "Enable Debuggers" section
check "Enable Native code debugging"
click OK to save the settings.
Now the debug should work.