How to build library against multiple target platforms - c#

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.

Related

Profiling .NET Standard DLL in VS2019

I am using VS2019 Professional to develop a Xamarin.Forms app. The project solution consists of the typical head projects which deploy to specific platforms, and the common cross-platform project that contains the bulk of the solution's code. I am trying to find some way, if possible, to run performance tests on the common cross-platform project, which builds to a .NET Standard DLL.
Xamarin currently does not have any tooling available to profile the platform-specific app using the DLL, so I need to find some other way. I have unit tests for this DLL, but there doesn't seem to be any support for profiling unit tests in VS2019. I have tried profiling the vstest.console application that runs the unit tests that test my DLL, but the only option available is to instrument vstest.console, which will do me no good either (obviously don't want to go mucking around with the guts of the test runner!). At this point it seems the only option is to develop an additional test console application and profile that, but I just wanted to check if anyone has encountered a similar use case and found a more elegant solution?

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.

Trying to create a solution with a monogame project and a class library, and it won't let me add a reference between them

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?)

Port Delphi.NET (ASP.NET 1.1) Project to ASP.NET 3.5 using C# in Visual Studio

i have an ASP.NET project written in Delphi.NET with Borland Studio 2006. Well it seems that the .NET Version is 1.1 and i need to port it to 3.5. My problem is that the project is a .bdsgroup and .groupproj. To make my work comfortable, i'd like to get a solution file .sln. What's the best way to this? (im not really sure i'm doing it all the right way. so if you have suggestions to make the port better, i'd please you to tell me)
thanks
First lets get a few things straightened out. Delphi.NET is both a language and a set of runtime libraries which attempted to recreate the RTL/VCL on the .NET platform.
Borland Development Studio is an IDE designed to edit multiple languages: Delphi, C++, C#, Delphi.NET.
If your intention is to port a Delphi.NET application to C# there are a few tools you can use. RedGate's .NET Reflector can generate C# from any .NET assembly regardless of the language that was used to write the assembly. I found it to be fairly useful at converting a Delphi.NET application to C#. Note: The generated code will still have dependencies on the RTL/VCL so you will still have to replace these with standard .NET equivalents.
If you are doing a Borland C# to VS C# port at least you're already in the same language. You'll just have to deal with library dependencies for the most part. If you already have the code working in BDS 2006 you can save yourself some trouble by replacing any borland-specific dependencies with standard .NET ones before you move to Visual Studio.
With proper separation of concerns and wrappers around third party libaries this is fairly straightforward. Unfortunately this is rarely the case. If your project is like most RAD style projects the business logic is embedded directly into the UI and library dependencies are directly woven into your code (this is rampant on any platform so don't think I'm singling out fans of Borland/Inprise/Codegear/Embarcadero). If this is the case you have your work cut out for you.
.sln file is Visual studio file, and not related to .Net or asp.net.
Delphi .Net has only support for .Net v2 (Delphi 2007), but you can switch your project to Delphi prism which support .Net up to verion 4, and work also from Visual studio IDE.
UPDATE:
I didn't know at first you are using C# project, so I gave my answer as Delphi, but if your project is c#, you can simply start VS and create new blank project, then add the *.cs from Project menu > add Exiting Files and point the *.CS files inside Delphi project, then save the Visual studio Project.
VS Doesn't read the *.bdsgroup files.

Sharing C# code between Windows and Silverlight class libraries

We wrote a small Windows class library that implements extension methods for some standard types (strings initially). I placed this in a library so that any of our projects would be able to make use of it by simply referencing it and adding using XXX.Extensions.
A problem came up when we wanted to use some of these methods in Silverlight. Although all the code was compatible, a Windows library can't be referenced in Silverlight so we created a Silverlight library that had links to the same class files and put compiler directives into the classes to allow different using declarations and namespaces. This worked fine until today when I added a new class to the Windows extensions library and realised that I would have to remember to link the class into the Silverlight library too.
This isn't ideal and I wondered if anyone might have ideas for a better way of sharing extension methods and other helper code between Windows and Silverlight projects.
You cannot set a reference from a Silverlight assembly to a regular .NET assembly but you can do so the other way round.
So create a shared Silverlight assembly and add your code to that assembly. Now you can set a reference fro both your regular .NET and you other Silverlight assembly to the shared Silverlight assembly.
The restriction is that you can only put code in there that would work on both the .NET and Silverlight CLR but that is no different from sharing code.
Since this question has been answered, there is a new solution from Microsoft, Portable Class Libraries. Here is the blog post where they announced it.
I'm just about to start playing round with them for sharing code between silverlight and some server side code I'm writing, so can't add too much past the links at the moment.
Silverlight runtime is different from the normal .NET runtime. So you need to do tricks at the project level to share code between multiple platforms.
Here's how I've done this for Autofac IoC container.
With this approach you do not have to create different projects for each platform being targeted.
PS: there is also a Project Linker tool from the Composite WPF that allows to link Silverlight and WPF projects (creates multiple projects). But it does look messy.
there is a similar problem with XNA projects. Since you can target several different platforms, you're required to have different projects. The reason for this is because the base class libraries that the project references are platform specific, so you can't have just one project.
If you're curious, you can get a bit of insight from this blog:
To recompile the source for another
platform, you need another project.
The reason for this is because the
projects need to reference different
assemblies for both the XNA Framework
and the underlying .NET Framework
(Xbox 360 and Zune use the .NET
Compact Framework), and C# projects
don't provide support for referencing
different assemblies for different
platforms.
Try this http://buildassilverlight.codeplex.com/
I had some dependency issues when referencing to a Silveright class library in .Net.
An alternative way when using Visual Studio 2010 and WCF RIA 1.0:
Create a normal .Net library assembly.
Create a Silverlight class library. In the configuration of the assembly specifiy the first .NET library as the "WCF RIA Service link"
Put your code in the .NET library as "ClassName.shared.cs" files.
WCF RIA will handle copying the file to the Silverlight assembly.

Categories

Resources