Cross platform C# and C++ VS2022 solution - c#

I'm currently converting a VS solution of a C# web application targeting .NET Framework 4.8, that has interop to C++ native libraries using C++/CLI as a bridge.
My goal is to port it to .NET 6, and make it all cross platform, so C++/CLI has to go. Also I need to make changes to my C++ native library projects which currently have dependencies to Windows SDK.
I've read that CMake is the way to go, and that VS 2022 has good support for it. I'm trying to set up a sample solution that has a single C# project and a CMake project, but it has proven to be very challenging.
It's like there is no such thing as a CMake project, but rather just a folder with a special CMakeLists.txt file.
When I add a CMake project it unloads the VS solution file, and the whole IDE changes to the Opened Folder mode. I cannot add an existing CMake project to a solution, because there is no project file.
The experience is sub-optimal.
The VS solution I'm trying to convert has a handful of C# and C++ projects, and it would be nice to be able to keep them all in the same solution.
Am I doing something fundamentally wrong? Should I be using something else instead of CMake?

Related

How to create Nuget package with C# and C++ libraries built with different options?

There is a project that wraps V8 engine into C# library. Its nuget package is broken and i'd like to fix it. Creating a package seems easy and there is documented way to pack different C# dlls for different .NET versions. However, i have no idea how to package .dll with C++ and C# code which could be built with different options:
x64 or x86 and not "Any CPU"
MS Visual C++ 2010/2012/2013
debug or release
.NET 4.0/...
I've found this thread and it seems that one can use .targets file with MSBuild commands inside. Then i've read in the docs that MSBuild way is old and not recommended. So what should i do?
One more question is: if this package depends on MSVC++, how to specify this? How to let package consumer select a specific version of dll (built against MSVC++2010, 2012 or 2013)? I suppose it is not a good idea to package msvcr*.dll.
Take a look at how the SQLite packages deploy their DLLs. With the 2.x and earlier versions of NuGet you need to write some powershell code to inspect the version of Visual Studio and apply your changes to the project manually.
We are working towards a more elegant solution for this exact problem with the updates that are to be deployed in NuGet v3

C# Setup with external DLL

I am trying to make a setup for a C# application in .NET 3.5.
The application runs an other application which was compiled for .NET 4.5 and uses some DLLs. I want to add this application to the application folder in the setup.
I can't add the DLL's to the setup as a file, there is an error popping up. ("The operation could not be completed")
If I add the DDLs to the project folder and then use them as content, I get an "Unrecoverable build error" when I create the project.
How am I supposed to add these DLLs? I do not care how, but I need them in the project folder.
Thanks.
PS: I am using the standard setup for VisualStudio 2008.
With Visual Studio, when you add your external DLL as a reference in a project, it will automatically be added to the setup.
First of all, isn't there any way to find an earlier version of the assembly targeting .NET 3.5? Or if you have access to the source, remove/change the .NET 4.5 specific code and recompile?
Otherwise, you can try to wrap you dll around a COM interface, as described here. This article targets .NET 4 dll used with .NET 2.0 but the mechanism should still work in your configuration. I have used it successfully myself for 2.0/4.0 interop.
Here is another trick you can try.
Consider that in either case you will need .NET 4.5 installed on target computer, in order to work. So you can move your project from 3.5 to 4.5. I understand that you use VS2008 which doesn't have .NET 4.5, but you can use express (free) edition of Visual Studio from here -> Microsoft Download Page
I solved this problem using a simple trick:
The errors came only from the DLLs written in .NET 4.5. The executable (.exe) did not cause any errors. What I did is to package all the DLL's into the exe using the ILMerge tool.
Then I added the .exe file to the library and everything worked like a charm.
ILMerge download site (Microsoft)

How to build library against multiple target platforms

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.

How to install an additional .NET library?

I'm a beginner .NET programmer (C# and IronPython).
I've come across WatiN .NET library which will show handy for what I'm trying to do. The website claims that it is compatible with any .NET language, so I assume it's compatible with IronPython as well.
How do I go about installing it? Their website only has some instructions, using NUget in Visual Studio. I neither use Visual Studio nor am I interested in it. How and where would I put the downloaded files in order to make it work with IronPython?
A library is a .dll file ( or many ), if you used nuget there should be a folder called packages in your solution folder and in there a folder with your dll.
What you want is to add a reference to that dll. Have a look at this

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.

Categories

Resources