How can I add a class to my own console app project - c#

I am facing this problem enter image description herewhen trying to add a new class to my project
Can anyone help me please

If you cannot add class to your project using IDE, as a workaround you can do it manually.
Go to your project's directory (where Program.cs is located)
Create new file named Class1.cs (you can give any name)
Go to Visual Studio and see is new class appeared.
If it didn't click on Show All Files, see your class, right click on it and choose Include in project
But this is obviously not a long term solution. Try repairing your Visual Studio using Visual Studio Installer

Related

No Solution explorer now showing Visual Studio

Here, the folder contains two files through which I can access the code of the project in visual studio: Program.cs & ProgrammingAssignment3.csproj
When I open the Program.cs file there is no Solution Explorer, which helps in accessing different custom classes.
Even if I tried adding it from the View window:
It doesn't show anything inside it.
I also tried Tools < Options < Projects and Solutions but there's no changes.
But here when I open this .csproj file:
The solution explorer is shown and also the classes.
But unfortunately, as I need program.cs file for my work, I can't use the .csproj file. And this not just for this project but every other too. Please tell me how should I get appear the Solution explorer in the program.cs file so that I can write code easily by accessing the classes. I don't mean I've problem with the .csproj file, I want the solution explorer to get running in program.cs file.
The class (.cs) is in your project (.csproj), and the project is always in a solution (.sln). The solution isn't accessible when its part of your Unity project.
If you open the project file directly from the file explorer you can edit the class program.cs from there.
You could also open the script from Unity itself and it brings you there too.
check if you multiple installation for VS
go to environment varaible and remove if you have duplicate entiries of old one
follow below steps:
tool Menu-->Import Export Setting--> Reset All setting --> Next ---> No Just reset my setting --> Next--> general development setting --> finish
it should fix the issue

Prevent Visual Studio from naming classes automatically?

Silly question: I am looking through the options in VS for something that will allow me to prevent VS from automatically creating (or at least automatically naming) the starting files when you create a new project. When I create a new Windows Form application, for example, and I name both the project and the solution "ExampleForm," VS will create the project but add a default Form1.cs file. I would think it would at least name the first file after the project/solution.
Is there any setting for this?
I think you will have to define your own Visual studio template

VS Wizard Template - Change Project solution and directory

I'm writing a Visual Studio Wizard Template using c# on visual studio 2012.
I followed the MSDN steps:
I created a VS template, then I created a Class Library project with a class which implements the IWizard interface, I configured the .vstemplate file and etc...
Now, my target is to write in the RunStarted function code, which does the following:
On the project creation, it copies another existing solution directory from another location to the new project selected location, and then, instead of creating the new project in a new solution, the new project will be added to the copied solution, in a specific "apps" folder, and no new solution will be created.
In the RunStarted method I wrote a simple CopyDirectory code which copies the wanted solution to the $SolutionDirectory$ which I extracted from the ReplacementsDictionary parameter. But now, I don't success to continue and change the new project configuration though it will be generated as a project of the copied solution.
Do you have any idea about this issue?
Thanks!!
You have 2 options:
If you have the DTE \ Solution2 object of the solution, you can use the AddFromFile() method or directly add the project from the template by using AddFromTemplate() method.
The current DTE object can be obtained by the GetService() method:
// Get an instance of the currently running Visual Studio IDE
DTE dte = (DTE)GetService(typeof(DTE));
If you can't get the solution as DTE object, you can edit the .sln file by using XML editing (look in existing .sln file how the projects added).

A project with an Output Type of Class Library cannot be started directly

Please can someone could explain why I get this error and what to do to fix it (or what I'm doing wrong!). The steps I have taken are
Download Source code from http://www.codeproject.com/Articles/16859/AForge-NET-open-source-framework
Opening in VS2010 shows the references cannot be found
Re-Add all 3 references from PlayingCardRecognition\bin\Release so no further warnings
When I try and build or Run I get the following message
To fix this issue, do these steps:
Right click the Project name in Solution Explorer of Visual Studio
Select Set as StartUp Project from the menu
Re-run your project
It should work!
If it did not work, be sure that you have set your start page. If your project is C# Windows Application or C# Console Application, try this:
Right click the Project name in Solution Explorer of Visual Studio
Select Properties
Select the Application tab
In the Output Type drop box
Select the correct application type of your project
Re-run your project and let me know if it won’t work.
The project type set as the Start-up project in that solution is of type ClassLibrary. DUe to that, the output is a dll not an executable and so, you cannot start it.
If this is an error then you can do this:
A quick and dirty fix for this, if that is the only csproj in the solution is to open the .csproj file in a text editor and change the value of the node <ProjectGuid> to the Guid corresponding to a WinForms C# project. (That you may obtain from a google search or by creating a new project and opening the .csproj file generated by Visual Studio to find out what the GUID for that type is). (Enjoy - not many people know about this sneaky trick)
BUT: the project might be a class library rightfully and then you should reference it in another project and use it that way.
.Exe's and .dll's are both assemblies. The key difference is that executeables define an entry point Main which can be invoked by the runtime. The error
"Class library cannot be started directly"
is due to the fact that said .dll's do not have a Main. To fix this issue, change the project type to a Windows application/Console application and define an entry point. Or, add a new project that is of type Windows application/Console application and reference said .dll.
The project is a class library. It cannot be run or debugged without an executable project (F5 doesn't work!!!). You can only build the project (Ctrl+Shift+B).
If you want to debug the code add a console application project (set it as the start up project) to the solution and add the reference to the library.
The project you downloaded is a class library. Which can't be started.
Add a new project which can be started (console app, win forms, what ever you want) and add a reference to the class library project to be able to "play with it".
And set this new project as "Startup project"
The project you've downloaded is a class library, not an executable assembly. This means you need to import that library into your own project instead of trying to run it directly.
Your project type is a class library one would suspect, add a ConsoleApplication or WindowsApplication and use that as your startup object. Reference this project and then access the code.
If you convert the WPF application to Class library for get the projects .dll file.After that convert the same project to the WPF application you get the following error.
Error:".exe does not contain a static main method suitable for an entry point".
Steps to troubleshoot:
1.Include the App.xaml file in the respective project.
2.Right Click on App.xaml file change the build action to Application Definition
3.Now Build your project
Goto the Solution properties -> on Build right side you see the startup project type. here you need to select the console appication/windows appication.
If you got this issue (got it in Visual Studio 2017 RC), and you don't get any of the things listed by Mak post from step 3 onward "4 In the Output Type drop box....", it is because you made a Class Library app when you want to create a cross platform app, so here is the solution :
1 Start a new project
2 select Visual C# and cross-platform app.
3 select cross-platform app (Xamarin and native app)
4 select blank form.
From then , right click, select as startup project and build as mentioned by Mak, and it should work.
If you can afford to start from scratch, it could do the trick as it did for me.
This could do the trick for the main issue as well, but must be adapted to your current version of Visual Studio ("Xamarin.forms portable" for visual studio 2015 for example).
Bye!
VS -> Debug -> Attach unity debugger -> double click project
Set your api project to a startup project:
Right click the api Project than choose Set as startup Project.
Just right click on the Project Solution A window pops up. Expand the common Properties. Select Start Up Project
In there on right hand side Select radio button with Single Startup Project Select your Project in there and apply.
That's it. Now save and build your project. Run the project to see the output.
_Sarath#F1
To fix this issue, do these steps:
Right click the Project name in Solution Explorer of Visual Studio
Select Set as StartUp Project from the menu
Re-run your project It should work!

Unable to access 'Build Action' property for .cs files

i got a problem with my site with my app_code files and a lot of question ive read people say you need to change the proprties of the .cs files to Build Action.
by right clicking the .cs files and press proprties.
but...
when i right clicking the files i cant see any option called proprties so i press F4 and it open a proprties window and i just click on the .cs file and still cant see any option i can change somthing to Build Action.
any idea why i cant see this options?
EDIT:
my problem is that when i get in the file proprties i have only 2 options...
thay are called:
1.Full Name
2.Full Path
EDIT2:
here what i see in visual studio 2010 when i try access the protrtie menu/window
http://img338.imageshack.us/img338/2359/blac.png
As Microsoft points out in the article "Web Application Projects versus Web Site Projects":
Web application projects use Visual Studio project files (.csproj or
.vbproj) to keep track of information about the project. Among other
tasks, this makes it possible to specify which files are included in
or excluded from the project, and therefore which files are compiled
during a build.
An answer to a similiar question at CodeProject's forums reveals a hint. Abstract:
[...] Looks like you are working on a web application that is actually a
Website as per Visual Studio. You would need to create a new Web Application
and probably copy over the source files there. [...]
http://www.codeproject.com/Questions/173637/Setting-Build-Action-for-Files-in-App_Data
Have you tried this:
You say you haven't got the option being suggested by other posters.
If this is the case, than it is quite possible that your Visual Studio settings are corrupt; this can give rise to all sorts of odd behaviour.
I would suggest you reset your settings, but please be aware you will lose any custom IDE settings that you've previously applied.
Try this:
In Visual Studio, go to Tools->Import and Export Settings
Choose "Reset All Settings" and click Next
Choose to save your current settings if you wish, or select "no" and then click next.
Choose the collection of settings( he IDE preset) you want, probably "Visual C# Development Settings"
Visual Studio will now revert all settings. Hopefully this will make the Build Action reappear.
[EDIT]
It might be worth trying safe mode too.
To do this, start up a "Visual Studio Command Prompt" from your start menu/programs list in Windows, and start Visual Studio with
devenv.exe /SafeMode
Does this make the options appear?
You can copy the file from Windows Explorer and paste it in the Solution Explorer. It will replace (or do nothing but incorporating it in the proj file) the file and recognize it as C#.
Normally you should see a Property named "Build Action" in the first line of the Property Window. This property should be set to "Compile".
Please select file and right click on it so that you will get following screen
Than click on the Properties you will get following screen
You can find build option in as a first option.

Categories

Resources