I have Java background and am trying to start on C#.
I wanna create a lib in C# that will be used in other solutions. In Eclipse it's just a matter of creating a jar and adding it to classpath. I know each project in VS2013 becomes a dll, but how can I make a solution see these dll?
Also, in Eclipse, we can create a Web Fragment Project. It can have Servlets, jsp and static js and css files, it becomes a war file and can be imported into another project and its files be used in that project.
How can I do that in VS2013? I'd like to create a solution with static files, master page, some aspx stuff, C# dll, and then use them all in other solutions.
Is there any tutorial (I googled it but found nothing) teaching how to do it?
You have a few options depending on your preferences and scope
Option 1 - The Class Library
You can create Class Library, that can be referenced in your website project. The Class library is a library of classes, interfaces, and value types
You can either Add an existing/New Class Library project to your website solution and reference it directly
You can add the project to your solution by right clicking the
solution (inside VS) -> Add -> Existing project -> and navigating to said
project's .csproj file
or
You can use a new/existing Class Library Project - build it and reference the built dll in your website solution.
you can right click your website solution (inside VS) -> Add -> new project -> choose Class Library
After you've done one of the above ->
Right click the project, you want to add the reference to
Click "Add Reference"
navigate to the .dll in question.
If the dll you want to reference is part of your current solution (as in step 1) -> after you've pressed "Add Reference" - press the "Solution" Tab and it should show up
After you've added the dll.
Remember to reference it in your code files with
Using TheReferenceNamespace;
which will allow you to call the functions inside you dll like the following
FunctionInsideDll(param);
or you could fully qualify your calls instead, like the following
TheReferenceNamespace.FunctionInsideDll(param);
Option 2 - Share MasterPages
if you just want "shareable" masterpages
you can do the following - (taken from this -> MSDN article)
(for future reference - web archive link - just in case something gets moved)
Precompile the Code Used in a Master Page
If you are concerned about code in your master pages being visible to others reusing the pages, you can precompile the master pages' code into a library. In this library, you can include code-behind pages as well as user or custom controls. Compiling master pages does not remove the declarative code for the master files or any server controls used, but you can compile the master files to remove the code for controls or code-behind pages used by the master pages.
If you choose to compile the master pages into a library, you must use the "updatable" build option that allows for later modification of the markup. This option is determined by the Allow the precompiled site to be updatable check box in the Publish Web Site dialog box. For more information about precompiling pages into a library that can be reused, see Building Re-Usable ASP.NET User Control and Page Libraries with VS 2005.
Option 3 - The template
Create a template, and use that template for different projects
In Visual Studio - Press "File" -> Export Template -> follow the wizard.
After it has been exported and you've imported it (either through a checkmark in the wizard or double clicking the vsix file) -it will show up under your project templates when you create a new project.
You can include a project from solution A in solution B by right-clicking on solution B and choosing "Add existing project"
Don't be afraid to edit XML .csproj files. For instance, this works ...
<Compile Include="$(Codez)\z.Libraries\diff-match-patch\DiffMatchPatch\**\*.cs"
Exclude="NotThisOne.cs;**\NotThisFolderWith\This*.cs">
<Link>Libs\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
...and will give you all the C# files from the source folder, and subfolders, as linked files in your destination project under a folder called \Libs\.
$(Codez) is a Windows Environment Variable I use on my PCs.
I also could have used *.* at the end instead of *.cs.
This is one of those things Visual Studio might break on you, adding a file into the folder full of wildcard-linked files may break them out to separate entries. Or not. Depends on the wind.
Related
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)
My situation:
I have a solution A with hundreds of projects,
Some of projects are class libraries and are referenced from other projects.
Now I want to create a new solution B which will consist of subset of projects of solution A. I start by adding the first pre-existing project into this new solution B. This project is referencing couple of class libraries from solution A. Therefore it is logical that these libraries cannot be found and I cannot build. Of course I could add all the referenced projects manually into the new solution B but that would take quite a long time, considering the total amount of projects that I need to add.
Is there some built in Visual Studio feature that can take care of this on my behalf? I.e. I will be offered an opportunity to import all the referenced projects at once and the B.sln file will be updated automatically.
I also have a ReSharper extension but I couldn't find such feature in there as well.
EDIT:
Some more detail on what I am trying to achieve. A.sln has lots of application projects and literally hundreds of class libraries. I want to create a new B.sln for one particular application project from A.sln and only add the class libraries that it is referencing, directly or indirectly... But the dependencies can go up to 15 levels deep so manually removing projects from original A.sln to create B.sln is really not suitable for me as I would have to carefully consider each one of the projects that I would be manually removing from the original sln file, subsequently reviewing the csproj files to find whether the application I am interested in does not indirectly depends on them via one of its direct references.
Copy paste your current solution file and start with it. Open it in new Visual Studio Instance. Remove your projects one by one. Instead of adding new projects, removing unnecessary ones will be more easy for you. As far as I know there is no such feature in Visual Studio as you want.
Removing will be more easy since projects are already there. Do not use Visual Studio to remove project but open sln file in suitable programmers notepad. Your projects are added to sln file as below lines.
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Integration.App1", "..\Example.Integration\Example.Integration.App1\Example.Integration.App1.csproj", "{E3977144-AFBA-451D-894C-1F89AA008041}"
EndProject
Removing such lines will be more easy if your projects has naming convention.
The best way to port references from an existing project that I've found is to generate a template for that project.
On the File menu, click Export Template. The Export Template wizard opens.
Choose project template and move through the wizard
Click Finish. Your project is exported into a .zip file and placed in the specified output location, and, if selected, imported into Visual Studio.
Now, when you setup a new project for solution B. You'll be able to choose the project template from A and all the file structure/references are preserved.
Ref: http://msdn.microsoft.com/en-us/library/vstudio/xkh1wxd8%28v=vs.100%29.aspx
I have merged another project in my existing project by right-clicking on the project name and selecting Add->Existing project option. Now i wan't to access the files from my newly added project from the existing one in Visual Studio (Its a C# project) , how can i do this?
If I'm following your question, you had a solution with a project A. You then added an existing project B.
You now want to access a file from A in B. If that's the case, right click on the B -> References and add a reference to project A. Now you can use the files from that project.
Edit: From your comment, I'm not sure if you want to have a separate project / file. If you want them to be only 1, you shouldn't really add a new project, you should add to your project A the files you need from project B. If you want to keep it as a different module that is included, then the above holds, but you need to realize that usually you have one solution, with many projects inside of it.
I struggle with this until I found this the link is below:
If you want all windows application to run as one program rather then calling multiple .exe. Then change 'Out Put Type' of each project to 'Class Library'.
Step 1:
You can do that by right-clicking on each Project in solution -> Go to Properties -> Application -> Out Put Type... set it to Class Library
Once you have done that output of these will be generated as .DLL.
Step2:
Add a new Window Form application project, add reference of exiting projects in it so that they can be executed from here.. you can do that by.. right click on main project-> Add Reference->Projects select all existing projects from here.
Now on the main application, you can create 3 buttons to launch each project...
[Inventory]
[Accounts]
[Payroll]
Now in each button code will be something like that...
Inventory_click()
{
Inventory.MainForm frm=new Inventory.MainForm();
frm.show();
}
Credit goes to forum post
I'm wondering if its possible to set up and share an entire folder of source code between multiple projects in Visual Studio 2012 like how eclipse lets you use multiple source folders. I'm currently developing an entity framework model for a game I'm making with split server and client code, said framework currently sits in a class library referenced by both projects.
The reason I'd like to use a shared code folder instead is to add code to each entity component type by declaring the classes in the shared folder as partial and having another partial class in the client/server projects that adds sided functionality. I thought that achieving this would be more useful than extending each component on both sides, and it would also eliminate the need to have a DLL included with the product.
you can add a project to your solution (right click Solution -> Add -> Existing Project) and reference it (right click on your project -> Add Reference -> Solution -> Projects -> "Project you want to reference")
You can right click on a project and select - Add - Existing item.... Within the open file dialog select the desired file, click on the arrow next to the Add button and afterwards on Add As Link
(source: modbusdriver.com)
I found something related here but did not give me a good start
Since recently I do a lot of webPart development I want to automate the none-code part of the process, I want to develop a small console app that creates SharePoint solution as the pic, i'll use it as a template for the upcoming webParts
assume the webpart name is a var
string webPartName = "usefulLinks";
Create Empty SharePoint Project
Add Visual WebPart webPartName
Create Classes Folder WebPartName
Create an empty class inside the folder
add the Layouts mapped folder
add css and img folders to the layouts folder
Change part of the .webpart content to custom values
Same to the Elements.xml file
add the Resources mapped folder and add two resources files for Arabic and English
and finally change the feature name to be like webPartName + Feature
any good starting points? or online resources
thank you.
What you are really describing is a custom SharePoint Solution Project, not a Visual Studio solution.
Project templates provide the files that are required for a particular project type, include standard assembly references, and set default project properties and compiler options.
This section in MSDN covers how to create project templates for Visual Studio. In particular, it sounds like the best option for you is the "Export Template Wizard", which will create a template based on an existing project you have created.