1.0.0-beta in Visual Studio 2015 - c#

I am trying to create a new c# class library in Visual Studio 2015 but when I to compile, the only option is "1.0.0-beta5" as the Framework.
I need this under 4.0. Why is it doing this?

I need this under 4.0. Why is it doing this?
Because you made a class library for ASP.NET vNext.
Is there an easy way to migrate this if I have to start all over?
I would just create a new class library, and move all code files there, which you then can include. The project.json and old skool csproj files aren't compatible, so you have to do the set-up by hand. So don't forget the references and the custom actions you might have.

You selected Class Library (Package) (the red in the image below) which is for ASP.NET 5 projects. You want Class library (the yellow):
You shouldn't need to start completely over - you should be able to create a new Class Library project, copy your files over and add them to the project.

Related

Share code between multiple .NET Core projects

I would like to know how I can share c# source codes between two (or more) .NET Core projects (commandline projects!).
As far as I understand, I can not link to source files in different directories in xproj/project.json based projects. I noticed that it now seems to be recommended to create nuget packages for everything. But is it really necessary for me to setup a private repository and create a nuget package only to be able to share some common source units?
VS2015 contains a template for .NET Core library which may be suitable for building a shared lib. Is it possible to link this lib to a project without a nuget package?
.NET Core Library is an excellent solution for you.
Do it the same way as in standard C# solution - just create the project and reference this project or add a reference to DLL file.
You don't need to use a Nuget, for your own purpose. Nuget packages could be useful to distribute your dll outside.
Clarification:
I miss one point - I'm using VS2015, but I have included Class Library project in my solution, and I'm referencing by project, not by DLL file, and this works fine in ASP.Net Core.
I also have a different project, where referencing DLL file directly working fine, but this is the previous version of ASP.NET app (not Core) - seems NET Core doesn't support this way like as the previous version (yet?).
Sorry for confusing you, sometimes it's too many technologies ;)
So could you just include ClassLibrary project into solution with your project and refer it as a project?
I have achieved this by using source control to branch from my commonly used projects in each new solution, and again merging back to the master branch if I make any changes.
Alternatively, baring in mind that NuGet is only an archived collection of files, you could keep this NuGet package locally, or even create a Template for Visual Studio that has the common libraries by default.
There are a wide range of possibilities that are down to your preference, and current environment state (I.E: Able to setup Source Control, or a package repository).

Visual Studio 2015 Class Library (I'm using C#)

I am working on a Windows Service Application. I have several classes in the project and I am trying to put these classes into a ClassLibrary so I can use those classes in the Service App Project, and also in a Console Application Project, so I can run the console version and step through the code. I don't want to re-invent the wheel here...
I have created a Class Library project, and I am having trouble updating the projects in this Solution to use these classes. In fact, when I moved all my classes into the Class Library project, they are all now throwing errors saying, "System" has no member "Data"! My A$$ it doesn't! Pulling my hair out.
Obviously, I have done something wrong. I've been programming since before there WAS a Visual Studio IDE, but this is SEEMING way more complicated than it should be.
Now my Service project cannot reference my Class Library project because the library doesn't have a .dll or .exe extension? I actually have to specify this somewhere, WhereTF do I do this? Isn't this the default behavior of a ClassLibrary? OMG! I just finished an iOS application, and NEVER thought that would be EASIER than a C# app! I did this in VS2010 easily, is 2015 really different?
It should take me no more than 30 minutes to move files from one project in a solution to it's own project, and then add a reference to that new project in the old one. Giving MS a MegaMindWedgie right now..
Don't need portability with RT hardware, just want 32-bit/64-bit computer apps.
All 3 projects are using the same namespace. I can't seem to add any references to the ClassLibrary project like I can in the Service project. It's blank. The only reference available to the Class Library project is .NETStandard,Version=v1.6
HELP...
It looks like you have created .NET Core class library. You can determine this based on the extension of the project file: *.csproj has been used with classic .NET framework projects, and *.xproj was introduced for .NET Core. Most probably, you don't need a .NET Core class library. So, your problem will go away if you create .NET Framework Class Library project.

Why create an ASP.NET 5 Class Library project?

I'm trying to figure out what an "ASP.NET 5 Class Library" (vNext) C# project has to do with ASP.NET. Why create a project with this template rather than just a regular C# "Class Library" project?
I like the new features, such as project.json file rather than .csproj file etc, but it doesn't seem right to create an "ASP.NET" class library when the project has nothing to do with ASP.NET or IIS etc. It's just a project for the business logic layer. A new WebApi ASP.NET web site will eventually reference this project, but that's not relevant at this point.
Is it just badly named? Should it just be called "vNext Class Library" and not use an icon that looks like a web app?
Why create an ASP.NET 5 Class Library project?
There are a number of benefits of ASP.NET 5 Class Library projects (.kproj) over Class Library projects (.csproj):
ASP.NET 5 class libraries easily support cross-compiling projects to multiple targets, such as aspnet50, aspnetcore50, net45, and various other portable class library variations. This includes rich Visual Studio support for Intellisense to notify you which APIs are available for which targets.
NuGet packages are automatically created, which is an extremely common thing to do with class libraries.
Better productivity when it comes to things like automatically refreshing Solution Explorer when the file system changes. Fewer conflicts in source control when trying to merge conflicting changes in the *.csproj file.
Can be compiled cross-platform (in part because it doesn't depend on MSBuild)
You can reference a *.csproj project from a *.kproj project (this was just made a lot easier with the new preview of Visual Studio 2015), but it was always possible with some manual steps.
Why does the name have "ASP.NET" in it?
As far as the names goes, it's a relic of history that will soon be addressed. The new project type is useful far beyond ASP.NET 5 applications. Expect to see new names in a future preview of Visual Studio:
.NET Console Application (Cross-platform)
.NET Class Library (Cross-platform)
Update 5/13/2015
With the release of Visual Studio 2015 RC you can see the updated project template names:
Class Library (Package)
Console Application (Package)
These use the project.json file and the .NET Execution Environment (DNX) to build, run, and package (into a NuGet package) the project.
These project templates continue to show up in the New Project dialog under the "Web" node, but now also show up in the main "Visual C#" node as well.
This is an interesting observation, the current template will generate a class library compatible with ASP.NET 5 runtime. You don't get that from the normal C# class library.
I filed the following issue for tracking this design question - https://github.com/aspnet/Home/issues/281
From what I understand one benefit is that the end product of ASP.NET 5 Class Library project is a NuGet package (rather than just the .dll assembly).
You can generate the NuGet package by right clicking the project in Visual Studio 2015 and choosing the "Publish..." option. Or you can use "KPM pack" at the command line.
Also, you have the ability to use the ASP.NET 5 Core runtime so that your library can run cross-platform .

add a c# library project to my project and how to use it

i have c# library project. i add it(library.sln) as a existing project to my project. so it comes to my solution explorer.
but in my forms when i try to access it, it seems it dose not exist using library; is noting !
where am i wrong, and what i need to do ?
it can not be build itself in visual studio when i try to debug project, the error is :
a project with an output type of class library can not be started directly
you can see the library project here http://www.codeproject.com/KB/selection/FarsiLibrary.aspx?msg=4043318#xx4043318xx and it have 4 namespace.
You need to use the "Set as StartUp Project" option in your context menu to set a runnable project. The project "library" you created is probably a class library which is not runnable.
Create some runnable project e.g. Condole application to use your library and set that as startup project. Then run your project.
Do not add an .sln to another solution. Add the Project (.csproj) instead.
When 2 projects are in the same solution there still is no link by default. Use Add Reference in the importing project.
Set an executable project as the Startup project.
A library is just a collection of classes, interfaces, enums etc.. In order to debug it, you'll probably want to create a console application that calls methods on your classes that you want to debug.
In addition, just adding the library to the solution is not enough for other libraries to be able to see them. In order to do this, you have to add it as a reference. You can do this by right clicking on the References item in your project, then Add Reference.
Rightclick on your references folder, press "add reference", switch to "projects" and add the reference to your library project.
Even if you add the project to your solution, you have to add a reference to that project for the WinForms project. This has nothing to do with the library.
If your WinForms uses .NET 4 Client Profile and the library requires .NET Full, then you can't access it and need to change the WinForms project to use the full .NET 4 runtime.
There are already good answers, but I would also suggest creating a Test project as a more efficient way of debugging the library.

Namespace cannot be found after changing target framework from v4.0 to v3.5

I have 2 projects in a solution, 1 a dll, the other an exe. Both were using .net version 4.0 however no 4.0 specific libraries were used so it should be possible for me to safely change them to 3.5
I did this under both project properties, I built the dll fine. Now when i try to build the exe it cannot find the dll's namespace. I have readded the reference, but it still cant see it. When I reverted the .net version it did say I might have to modify the project files before it builds. I have tried to search for a solution via google but the key words I am using are too commonly used. Can anyone advise?
Many thanks, Chris
Edit:
Tried the following already..
Reference DLL specifically whilst ensuring not 4.0 copy
Delete bin and obj folders
Restart VS
Rather than referencing the output DLL, have you tried setting it as a project reference instead.
Also, have you done a clean build of the solution incase any .Net 4.0 files were lingering? You can manually clean the project by deleting the bin and obj folders.
Have you tried removing the projects from the solution, creating a new .net 3.5 project and compiling that. Then add in the ddl project (Add -> existing project) and compile, then add in exe project without reference, compile then add in the references.
Odd question, but have you check the name spaces still. Can you call in your project the namesapce, i.e. using mydllproject.model.myengine
I would open your project files as XML. To do this, close the soltion and reopen the projects only by clicking the down arrow on the File/Open button and selecting Open With... XML (Text) Editor. Check to make sure each project has a ToolsVersion="4.0" in the header. Check the RootNamespace and TargetFrameworksVersion elements to see if they have the values that you expect. At the bottom of the file, check the ProjectReference element within the ItemGroup. Make sure the GUID in the project reference matches the GUID that is defined in your solution file.
Finally, make sure you clean your project before you rebuild it. If you're using source control, check out the project into a new, empty sandbox.
Good Luck!
-Put dll and exe in 3.5
-Compile the dll only
-Delete the reference to the dll and readd it
-Rebuild the solution
Check the DLLs that you are referencing what kind of target runtime they require, especially the "Engine.dll". You could do this with the .NET Refractor for example. If they are compiled for v4.0, then yuou need to get versions for an earlier version of .NET runtime.
I had a very similar problem to this. In my case it I had two projects, a 'class library' and a windows forms application in the same solution.
After changing the target framework of both the projects to .NET4.0 framework, and adding a reference to the class library in my windows forms application, it wouldn't detect the namespace of my class library.
Here is what I did that finally solved the problem:
Created a new project with .NET 4.0 framework as the target framework. I imported all my forms and classes into this project from the original solution.
Added the existing class library as a new project.
Added a reference to the class library project from my windows forms project
For each of the class files under the class library project, I set the 'Build Action' to 'Compile'
Right-clicked the class library project and selected to 'Rebuild'.
Then when I go into my windows forms projects, I can see the namespace when I use the
'using namespace_name' statement.
Note: Maybe you do not need to create a new project like I did in the first few steps. But changing the Build Action definitely did the trick.
Hope it helps.

Categories

Resources