金宝app支持的平台:Windows®(作者),Linux®(执行),以及macOS(执行)。
This example shows how to create a .NET assembly using theLibrary Compiler并将其集成到可以在Linux或macOS。
Create a new work folder that is visible to the MATLAB®搜索路径。此示例使用C:\Work
as the new work folder.
安装MATLABRuntime在Windows和其他平台上,您打算在其中运行.NET Core应用程序。有关详细信息,请参阅安装and Configure MATLAB Runtime。
对于Linux和macOSplatforms, after installingMATLABRuntime,您需要设置ld_library_path
anddyld_library_path
环境变量。有关更多信息,请参阅Set MATLAB Runtime Path for Deployment。
验证您有视觉工作室®和.NET Core 2.0或更高安装。如果已安装了Visual Studio 2017的15.8.2版,则无需单独安装.NET Core 2.0或更高版本。
使用Library Compiler应用程序。另外,如果要使用程序化方法从MATLAB命令窗口创建.NET组件,请参见compiler.build.dotNETAssembly
。
创建一个名为NEW MATLAB文件mymagic.m
在工作文件夹中使用以下代码:
functionout = mymagic(in)out = magic(in);
TypelibraryCompiler
在MATLAB命令行中启动库编译器应用程序。
In theTYPEsection of the toolstrip, select。NET Assembly
, and in the导出功能section, click the添加按钮添加文件mymagic.m
到项目。
In theLibrary informationsection, name the libraryMyMatrixFunctions
。
双击班级Class1
and rename it asMyMagic
。
使用默认项目名称保存部署项目MyMatrixFunctions
。
选择Package创建.NET组件。有关创建文件的信息,请参阅包装MATLAB功能后生成的文件。
在Windows中打开命令提示符并导航到文件夹C:\Work
。
在命令行,键入:
dotnet新控制台 - 名称mydotnetCoreApp
This creates a folder namedMyDotNetCoreApp
that has the following contents:
OBJ
文件夹
mydotnetcoreapp.csproj
项目文件
program.cs
C#源文件
在文本编辑器中打开项目文件。
exe netCoreapp2.0
添加the following references to the project using the
tag:
.NET组装文件mymatrixfunctions.dll
created by the Library Compiler app
MWArray.dll
,位于
\ toolbox \ dotnetbuilder \ bin \ win64 \
Once you add the references, your project file should resemble the following:
exe netCoreApp.2 <参考> c:\ work \ mymatrixfunctions \ for_redistribution_files_only \ mymatrixfunctions.dll <!<!<! - 由库Compiler App创建的.NET组装的路径 - > <参考:\ program文件\ matlab \ matlab runtime \ v97 \ toolbox \ dotnetbuilder \ bin \ bin \ win64 \ v4.0 \ mwarray.dll.dll <! - path to matlab runtime-runtime-runtime-> 参考路径>
Open the C# source fileprogram.cs
并用以下代码替换现有代码:
在命令行,通过键入构建.NET核心项目:
dotnet构建myDotnetCoreApp.csproj
At the command line, run your application by typing:
dotnet run -3
该应用程序显示一个3x3魔法正方形。
将项目作为独立部署发布,以在Linux或macOS。
To publish to Linux, type the following command on a single line:
dotnet Publish-configuration Release-Framework NetCoreApp2.2--luntime linux-x64-固有的true myDotnetCoreApp.csproj
To publish tomacOS, type the following command on a single line:
dotnet publish --configuration Release --framework netcoreapp2.2 --runtime osx.10.11-x64 --self-contained true MyDotNetCoreApp.csproj
复制Release
文件夹来自c:\ work \ mydotnetCoreApp \ bin
on Windows to~/Work
on a Linux ormacOS机器。
On the Linux machine, verify that you have installedMATLABRuntime并设置您的库路径环境变量。有关更多信息,请参阅Prerequisites。
打开命令外壳并导航到:
〜/work/prease/netCoreApp2.2//发布
通过键入运行.NET Core应用程序:
。/MyDotNetCoreApp 3
顺序的魔法平方3 8 1 6 3 5 7 4 9 2魔法正方形作为本机数组:元素(0,0)= 8元素(0,1)= 1元素(0,2)= 6元素(1,0)= 3元素(1,1)= 5元素(1,2)= 7元素(2,0)= 4元素(2,1)= 9元素(2,2)= 2