Is it possible to create 'invisible' project using Visual Studio addin? - c#

I have an idea to create some sort of extended Immediate Window VS plugin. I've noticed that when I want to test something (like new Regex or DB reqest) I tend to create new console app for this. The idea is to create project that is not included in solution and references current project and has all using directives from current file. So I'll have all advantages of code editor: usings (no full class names), syntax highliting, IntelliSense, multiline commands, other plugins (R#/CR).
Is this possible?

Option A: Write those in a test-project added to your solution
Option B: Create a console application added to your solution
Create a build-script that only builds the projects you want to give to your customers.
To gain some ideas: look at http://mvcstarter.codeplex.com/ (point 9)

Related

Build Library To Automatically Referenced Locations with Visual Studio

I would like to remove a step of the process when building libraries in C# with Visual Studio, like how the System libraries can simply be referenced by adding the statement: using System to the top of the file.
Normally when building a class library, you have to add a reference to the library in the project you want to consume the library from, and then you can add the using statement on the top of the file you wish to reference the library from.
Is there some way to remove the step of needing to explicitly add a reference (the step accomplishable via a right click on the project in the solution explorer in Visual Studio)? Perhaps by building class libraries to a specific location that Visual Studio automatically adds as referenced when creating new projects to consume the library?
The end goal is to be able to write C# class libraries, and simply have them available whenever I am writing an app, without needing to explicitly add a reference to each library in each new app I write. Whenever I want to edit a library, I could simply open that Visual Studio project, edit it, and then build it again. Then the updated library is available to all of the apps I have consuming that library.
I'm not sure why would you want to do this, cause it's a simple thing to set the using statements in the top of the page. But i'm almost certain that you can't get arround this.
This post states that: answer to get around of using statements

Create a general "skeleton" from a c# project

I've a very complex solution in c# containing about 20 projects, each of them control a device since it is a driver.
In many cases those projects use similar structures/code (for example everyone as a connect method, a retrive data method and so on).
Is there a tool to analyze the code and create a general "Skeleton" that can be reused?
You can easily create a project template from an existing project from the File>Export Template menu. The process is described in How To: Create Project Templates.
There is no tool that can decide what to include in a skeleton project, as this depends on knowledge of what each project actually does, which parts that can be generalized and which have to be project specific.
You can use duplicate analysis in Visual Studio or Resharper to find repeated code, but this won't tell you what should be in a template and what shouldn't.
What you can do, is:
Extract common functionality in a separate project that all device projects will reference
Create a template from one of the device projects.
Use template parameters to customize the resulting template.
Step #1 will result in a much simpler template, that is easier to customize

Safely rename a namespace of a specific project in a solution in VS 2010

In, Visual Studio 2010, I have a solution with various projects and I have two projects that share a C# namespace with the same name, however, they are intended to be separate namespaces.
I want to rename both namespaces to different ones to prevent confusion. However, I wonder if there is a safer solution other than having to use Ctrl+H and choosing to replace all the occurences in the project.
I know you can just retype the name of a namespace in code and VS will ask to you if you want to rename all occurences, however I don't know if VS will be smart doing this to each project separately, and it says if I rename it I cannot undo the action because it will be applied to too many files. I also tried to open a project alone to prevent this but VS automatically opens the whole solution.
You can use a refactoring tool such as Resharper to do this safely.
There are also other tools available, but I usually use this because it works very well for me.
Copy the folder that contains your solution, and projects, to another folder (just in case)
Create a new solution with just projectOne inside and perform the refactor of that namespace there.
Create another new soution with just projectTwo inside and perform the refactor of that namespace there.
Open the original solution, thas has those two projects inside, and see if the results are what you expected
You can load the projects one at a time and refactor the namespaces as you wish. Open the entire solution and unload one of the two projects.
If you want advanced refactoring, you can try DevExpress' Refactor Pro or ReSharper. Both are awesome refactoring tools.

A project with an output type of class library cannot be started directly (2)

A project with an output type of class library cannot be started
directly. In order to debug this project, add an executable project to
this solution which references the library project. Set the executable
project as the startup project.
While running the program in C# visual studio 2010 I am getting this error. Please tell me how to sort out this error?
Set your startproject in the project explorer by clicking right mouseclick on an executable project and choose "Set as start project"
You created the project as a class library project, not an executable program. Class libraries are compiled and then used by other applications for common functionality.
If you meant to create a class library, you need to create a test application (or, better yet, Unit Tests) to test the functionality. If you meant to create an executable application, you'll need to modify the project.
If you have multiple projects in a single solution, you might also need to make sure you have the correct project set as the "Start Project" rather than one of the class library projects.
what you have done is that you have made a class library with all your code
every project in .Net needs a starting point like Main() function in c# which obsly isnt present in a class libraty type of project
what you can do instead is
1. Make a console project inside the same solution. by right clicking the solution and add new project
2. Add a reference to the class library
3. Access the classes/methods of the class library and then starting the console project instead of class library project
Alternatively,
If you have a console project OR any other project in the solution already
right click the project in the solution explorer and Set as Startup project
Right click on Solution-->Go to properties-->Expand Common properties tab-->(On right side) Select Radio button with option Single startup project-->choose project from drop down list.
Enjoy.
If you want to debug code in the DLL or run it using tests, go to the properties of the project, go to the Debug tab, select "Start external program" and enter the name of the application to use, such as a test runner.
Go to your project properties page, change Output Type to Console Application or Windows Application (depending on what it is).
Make sure that you've got correct project set as startup one (right click -> set as startup project), and that this one is not of type Class Library. If your only project in solution is class library, then you need to create some test executable for it.
The same error type i have found in my one of project suddenly which is running in VS 2012 with MVC 4 only. I have run multiple ways to resolve this error, but i have found filly with small change option in Property window of your respective error giving project.
I have went project property window there i have change startup Project from Healpars to Myproject.Then it is working fine.
Thank you
I was surprised to learn that you can indeed set some Class Libraries as Startup and run them, IF they contain user controls. They run in the UserControl TestContainer which allows one to modify properties, etc. Basically debug at DesignTime, which can be really helpful. I have about 20 user controls in a single Project. This way I can run the TestContainer and choose which user control to run and debug.
If it is a function app project that you want to execute then you need to have Azure development tool installed in your visual studio. Please see the below image for more info.
enter image description here
You need to mark the API in the set as startup project
Right key on the API
select .net core project, then it will start directly with no doubt. Thanks

How to Create a DLL file in Visual Studio C# 2010 Express edition?

I have already come across the Stack Overflow question "Is there a way to generate a DLL file from Visual Studio Express without explicitly creating a DLL project?", but it does not directly answer my query, so I'm raising it here.
The problem I am facing while trying to make the DLL is that I can't find any option under Build named build class file.
I have changed the project property to class file (shown below)
This is how it is:
And here is how my build option is getting displayed:
Also when I am using the command-line option the dll file is getting generated but it is not getting the properties I'm setting in the application.
I am new with Visual Studio so a litte bit confused about this part.
The "Build Solution" option in your second screenshot is the thing you need to click to produce your dll, alternatively you can right click on your project in the Solution Explorer and click "Build":
(If you only have one project in your solution then these two will both do exactly the same thing)
The output dll will normally be placed in the bin\Debug or bin\Release directory depending on whether you are in Release or Debug configuration, check the "Build" tab of the project properties for the exact path.
The reason why you aren't seeing a "Build class file" option is because this is what the "Build project" menu item does - it will produce a class library if the project output type is "Class Library", a windows executable if the project output type is "Windows Application" etc...
You're not trying to build a class file - you're trying to build a class library.
And you just build the solution - that will build each of the projects in your solution, including your LicenseCheckLibrary project is just a class library project.
It looks like you're basically there - look in the bin\Debug or bin\Release folders under LicenseCheckLibrary, and you'll find the DLL.
Why would you want to avoid building a DLL file in the first place? Are you developing an EXE file in order to test the logic and then conver it to DLL once it is working fine? If yes, why not create two projects: Windows Console and Class Library. Inside Class Library implement the licensing logic and use Windows COnsole to test the logic. When you say you are new with Visual Studio, what exactly do you mean? You never used it before or you are new to .NET Framework programming? .NET Framework has certain classes for developing licenses. Also, there were quetions here on stackoverflow regarding the licensing. Find some of them instead of reinventing the wheel.
Have a look at this article http://www.developer.com/net/net/article.php/3074001
Create a new class library project
Create classes and code
compile Project
Dll Created
Create a new project
Click on Add Reference
Navigate to the class library folder
Go into the debug folder or whatever and include
Remember you will prob have to include the namespace. in the new
project.

Categories