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.
Related
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.
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 .
I wrote a game in XNA a while ago, it just has two projects - a game, and a library. It worked fine, and now I am porting it to Monogame.
I have created a MonoGame Game project, and a Class Library, and put all of the files from my old XNA project into them. The Class Library builds with no problems or errors. However, it won't let me add a reference to it from my other (game) project.
It just says "Unable to add a reference to [MyLibrary]"
I read something about it possibly being because they target different frameworks - one targets .net and one targets ".net CORE" but I don't know if this is the case, or how to fix it.
Can anyone advise me on what I should do?
You're probably right about the framework targeting issues.
There are a few ways to deal with this, the first is to try and change you're library to a Portable Class Library. They are designed to be able to target different frameworks including the different frameworks MonoGame supports.
http://msdn.microsoft.com/en-au/library/gg597391.aspx
The downside of portable class libraries is that they only support a subset of the full .NET framework. If that's the case you'll want to try and change you're library into a Mono for Android Library project (or whatever framework you're targeting).
If you want to build for multiple target frameworks and need to minimize the amount of duplicate code in each project I think your best bet is to add the files as 'links' to each projects. It adds a bit of maintenance but allows you to edit a file in one project and have the change made across all projects.
If I were you I avoid the Portable Class Library both for the reasons that #craftworkgames specifies, and also from my own experience of developing a Windows 8 App - they just cause you hassle. While it's good from a design principle to separate your classes into a library of their own, I would just add them all to your development project (unless you're writing an API that you want the world to be able to use?)
I'm asking this question due to Silverlight and NUnit, that if you've tried, know they do not play well together. Basic reason being SL code is compiled against the SL framework, and NUnit is compiled against the standard .NET framework.
Anyway, I've got a bunch of classes that are not specific to SL but do reside on the client side. I was thinking about moving them into their own library. Is it possible to configure Visual Studio and/or solution to compile this library both as an SL library AND a .NET library?
My SL client app would reference the SL-version of the library, NUnit would reference the .NET-version.
I'm suspecting at best, this would have to somehow be arranged through the makefile, and the NUnit test project could not reference the project directly, but rather the .dll created.
And other issues like that.
Just wondering what peoples thoughts are on this idea.
Like you were planning to do, you could create SL Class libaray and .Net Class library and have the code in one project and do file link in the other project. This way you do not need to keep two copies of the files. So you can point to the .net class library for the NUnit tests. Just a thought.
Sounds like a job for Portable Class Libraries VS 2012 has built in support and there is an add-on for 2010.
I'm writing an application in .Net 3.5.
I have 3 projects in the solution so far. When adding the references to the other projects from my main project, the intellisense manages to find the classes from the other project's dlls but at compile time it seems to be "loosing" the reference.
This might be because I initially created the project with target framework .Net 4.0. However since I needed to use the ASP.NET web services I had to downgrade to 3.5.
Any help will be greatly appreciated.
The referrenced projects must be Copy Local : True
Referrence -> Properites ->Copy Local : True
Batch clean all projects in your solution, make sure all the projects in your dependency graph target the .NET 3.5 framework. Check the reference's HintPath in your .csproj file (open with text editor) for references to external DLLs and make sure they're all <=3.5.
However since I needed to use the ASP.NET web services I had to downgrade to 3.5.
There are also several different web service projects in .NET 4. I don't quite understand this move.
You have project references, intellisense sees your referenced classes but when compiling, the compiler seems not to find the referenced assemblies.
I see two possible reasons for this behaviour:
Your main project references a lower version of the .NET framework than your library projects (this is the most likely cause).
Your library projects won't get built at all / or in the wrong order (check the settings in the configuration manager. Open it with a right click on your solution in the solition explorer).