Building Rust project alongside .NET Core - c#

Is there any way to build a Rust project with a C# .NET Core project when invoking dotnet build? The project structure is as follows:
<Root>
> Engine
Main.cs
> Native
> src
lib.rs
Cargo.toml
Root.sln
I am using P/Invoke to call the rust Native library from Engine, and I want a convenience step to build both the rust project and the c# project when dotnet build is invoked, including setup such as copying of the rust Native library into the output folder of the c# project etc.
Extra: If possible, is there any way to 'bundle' the Native library into the compiled c# Engine?

Related

dll file export issue for c++ project

I have a .net core project and c++ project under same solution. When I build the solution or the c++ project, it outputs files .ilk, .exe.recepie, .obj etc files. I need it to ouput .dll file so that I can import it into my c# project. Can anyone tell me how to do that?
Also I don't want to change architecture of the c++ project to win32 because I use opencv in c++ project and if I use win32, it will not work and I feel it might run faster in x64.
I'm using Visual studio 2022, latest opencv, .net core 6

Is there a way to restrict .NET Core projects to generate only .dll as output files when using .NET Core 3.1 sdk

When i build my .NET Core Console Application using .NET Core 3.1 sdk,it generates both .exe as well as .dll as output. When i was using .NET Core 2.1 it was generating only .dll as output. Is there a way to restrict .NET Core 3.1 sdk to generate only .dll as output?
You can control this with the UseAppHost MSBuild setting:
The UseAppHost property was introduced in the 2.1.400 version of the .NET Core SDK. It controls whether or not a native executable is created for a deployment. A native executable is required for self-contained deployments.
In .NET Core 3.0 and later versions, a framework-dependent executable is created by default. Set the UseAppHost property to false to disable generation of the executable.
<PropertyGroup>
<UseAppHost>false</UseAppHost>
</PropertyGroup>
If you want to disable this when building from the command line, instead of setting it within the .csproj, pass the property as an argument. For example:
dotnet build /p:UseAppHost=false
In .NET, the difference between a .exe and a .dll is actually very small. .exe tend to be little more then .dll's with some bootstrap code and a start point (the class whose main method is to be called).
You can use both .NET .exe and .dll as project references. There might be some difference in some fringe details like COM interop, but I do not expect it.
What exactly the compiler will build, depends on it's inputs. Wich includes the project settings. There is a special type of project for library. And with version changes, the proper reading of projects files could be broken. And of course the option that some code is "seperated out" into a .dll is also there. Most programms nowadays are more .dll's then executeables. And it can be beneficial to keep .exe small.

Using custom C# class library in another project

I built a class library as a NuGet package to be used in another C# project. When I built the class library, I followed a tutorial that suggested targeting .NET Standard 2.0.
I installed the package into the other project and it builds fine. However, I've noticed that the output folder contains several other 'System.' dlls (ie. System.AppContext.dll).
In the past, when I've built a class library for C++, I did not get the dependent dlls copied to the output folder. I had assumed that building a C# class library would act the same way. For C++, those dependent dlls are resolved at runtime by the C++ redistributable dlls. I thought the same would be true in that C# would resolve them through the installed framework.
So, I'm a bit confused as to why the extra dlls are present in the output folder. Is it because I targeted .NET Standard 2.0? Do I need to ship the extra dlls with my application?

how to use a .net dll with static utility functions in unity 5?

I have a .NET 3.5 .dll build with VS2015 that contains some static utility functions and has no further dependencies. What I want to achieve is to use those utility functions in a C# Script in my Unity 5.5 (personal edition) project.
I dragged the .dll into the assets browser and created a new C# Script. Unfortunately there was no automatic reference to the .dll, and I wasn't able to find any possibility to add one.
This is what unity shows when doubleclicking on the dll:
How can I use my (not in any way to Unity related) dll in my Unity C# Script?
Unity runs on Mono not on .NET - that's different things.
Use one of Unity target frameworks (set in VS project properties) when compiling dll outside Unity environment or use PInvoke.
Put dll file into "Plugins" folder.

Cannot reference IronPython Project from C# Project

I am trying to reference an IronPython project in a C# Project. They are both in the same solution. I am new to IronPython, so I was just wondering how the referencing works. Does an IronPython generate an assembly at all? All Im trying to do is a pull a simple class into the C# project.
any ideas?
Thanks.
Edit: I'm not getting any error, I just cannot figure out how to reference the Ironpython project.
If you are using IronPython Tools for Visual Studio then an IronPython project will not be compiled. To compile IronPython code to a .NET assembly you can use the IronPython command line compiler pyc or SharpDevelop.
A compiled IronPython assembly cannot be used from a C# application directly without the application hosting the IronPython runtime. When the C# application hosts the IronPython runtime you can then either use the IronPython script files (.py) or the compiled IronPython assembly, as explained in the two articles below, both of which use IronPython 2.6.
Using Python Classes from .NET
Using Compiled Python Classes from .NET
The first article shows an example where the IronPython code mixed in with the C# code. You can alternatively load the IronPython code from files by replacing the call to CreateScriptSourceFromString with CreateScriptSourceFromFile or by using the .NET Framework.
As far as I know IronPython only creates .py script files - you can access the code through the DLR at runtime, there's an example for that here.

Categories