Dear list, I'm having trouble to import assemblies with certain names. I found it impossible to import assemblies named "Library", and I cannot import arbitrarily named assemblies that live in a subfolder having the same name as the assembly. Here are some details of a working configuration (MWE): mylib.cs:
namespace mylib { public static class mylibClass { public static double DoubleThis (double x) => x*2; } }
mylib.csproj:
<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Platform>AnyCPU</Platform> <OutputType>Library</OutputType> <OutputPath>bin\</OutputPath> <DefineConstants>TRACE;DEBUG</DefineConstants> </PropertyGroup> <ItemGroup> <Compile Include="*.cs" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
build with "msbuild mylib.csproj", copy the .dll from the bin directory to the python script (avoid modifying the path). Python (3.6.6 from Anaconda):
clr.AddReference('mylib') import mylib print(mylib) print(mylib.mylibClass.DoubleThis(3))
This will print "
участники (1)
-
Johannes Strecha