Change where Unittest projects is created - c#

Visual Studio 2013/2015 makes it possible to generate Unitettest projects and methods by right click direcly on a class method. If the project is missing, then it will be created and the problem is that this project will be created at the root of the solution, is there any way to change this so it is placed within a specific Test folder?
BestRegards

There is no way and its no point to try to defy.

Related

How to use a class of one project in another project under the same solution?

I have two projects of Web API and Windows Forms App under one solution.
The names are:
Solution - CliendAddress
Web API - ClientAddress
WFA - ClientAddressWFA
In the ClientAddress project there is a class called ServiceResponse. How can I use this ServiceResponse class in my project ClientAddressWFA?
From my ClientAddressWFA, I've already added the reference to ClientAddress 👇
However, when I am trying to add using ClientAddress.Models; (<---- This is where the ServiceResponse class is) in my ClientAddress.WFA project, I'm getting an error👇
Recording: https://screenrec.com/share/XTp0dwbI42
If you need just this one source file then you can just add it to the other project "as link". Quick and dirty, but who cares. However, if you need more classes, then make a shared library project that would then be referenced by both projects. That's what shared libraries are for.
So, in project ClientAddressWFA try to add this one .cs file but instead of clicking "Add" click on small triangle next to "Add", and select "Add As Link".
Sometimes just restarting the visual studio and compiling again will work (Given that class you are referencing from another project is public and you have added project reference)

Where to define files required by many projects in visual studio?

Let's say I have 5 or 6 projects in my solution. There is a file called fileCopyHelper.cs that basically copies files from one folder to another. I need this file for a lot of projects in the solution and I don't want to keep redefining it in every project? How do I do it?
I tried adding a .cs file to the solution and Visual studio grouped it into Solution items folder. However I'm unable to access the classes defined in this file in my projects because Solution items is just a folder, not a project, so I can't add a namespace reference from other projects.
Add a new project to your solution, and select the class library type. This gives you a single place to add code that will be shared.
Reference the new project in whatever other projects in your solution need access to the code.
Your setup might look something like this, where the fileCopyHelper class is party of ClassLibrary1, which is then referenced and used in the main ConsoleApp1 application:

Add programmatically Visual Studio Solution and Projects

I am trying to generate a Visual Studio 2010 solution and add VS 2010 projects from custom templates!
My requirement:
1. Generate a VisualStudio Solution 2010, Save it to a folder, add VisualSTudio Project from my own templates (I have 3 different templates: ClassLibrary,WinForms ,WCFService)
My issue:
I implemented something that is working half a way!
Solution is created correctly but the content of the ".sln" file is very poor! No project reference is added >
In the root folder, it creates a Solution also for the C# Project, which I do not want. I want only the MainSolution file. (In my case "TestSolution.sln"). How can I stop creating a solutionfile for each project created?
Below the source code I use:
//for The solution:
//adding a project
Am I using the wrong interfaces?
Why the vs2010Solution.AddFromTemplate(..) returns null after the call, but no exception is thrown? Also the Project is created correctly in the folderstructure! But at runtime I can't check the list of projects "vs2010Solution.Projects" as it is null! (After correctly adding a project). I need the Project added because I need to add some references programmatically, which I try to do in the next line, but it doesn't work because vs2010Project is null).
So I am trying to wrap the VisualStudio 2010 automation model, to create a solution and add projects! But is not really working! Do I need to cast EnvDTE.Project to "VSLangProj.Project" at some point? I want to create a clean wrapper for VS2010, after that one for VS 2012!
Any help is much appreciated.
See the several articles of the section "Articles about automating project creation" on my web site:
http://www.visualstudioextensibility.com/articles/add-ins/
They explain why AddFromTemplate method returns null, how to create a solution, a project, a project inside a solution folder, a project item, etc.

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!

Why do I have to delete `bin` folder of my project before each build?

I am working on a C# application which I have divided it to few projects. Recently when the solution becomes larger, I get different errors such as MissingMethodException or even worse, DLL not found messages.
The only solution is to delete my bin folder and build the project again.
I wonder if this is a common problem with visual studio or might be I am doing something wrong?
UPDATE:
I am working on a winforms soloution, while one project is the form and other projects are user control, data models and etc.
I do reference the needed project in other projects using the visual studio's add reference option.
UPDATE 2
I am suspecting when I have a new .cs file to extend a class using partial keyword in any projects this happens!!!! I am 99% sure, I am going to check some more times to see of this is really the case!
It's not really a common problem but messy things can happen some times on visual studio.
What I would do is to check the settings and dependencies of every project and check things like they build in the correct order, platform, output path, etc. In our case, some times when the solution travels to many developers/computer settings can alter.
Also another thing you could do would be to copy the main project to a new solution and add the rest of the projects. This has worked form me in a similar situation.
I hope I gave you some ideas.

Categories

Resources