vscode搭建Aras开发环境

445 阅读1分钟

序言:这篇文章很早之前便想发了,本意是想写一篇长文,可是最近忙于其它事情,感觉忙完都不知道得多久,所以打算把Aras Innovator开发分成短文发表。这篇文章主要讲的是使用vscode对Aras Innovator的开发环境搭建,使用vscode的原因是我目前使用的是公司的电脑,虚拟机装Visual Studio会很卡,所以暂时使用vscode,以后会写Visual Studio开发环境搭建。

  1. 新建一个workspace的目录

  2. cmd的方式打开目录,执行dotnet new console -n HelloAras命令,会在该目录创建一个名为HelloAras的控制台项目。

  3. 使用vscode打开该目录

  4. 编辑HelloAras.csproj文件,原文件格式如下:

    <Project Sdk="Microsoft.NET.Sdk">
        
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
      </PropertyGroup>
        
    </Project>
    
  5. 新增dll引用,将C:\Program Files (x86)\Aras\Innovator\Innovator\Server\bin目录下的IOM.dll拷贝至根目录(也就是HelloAras.csproj文件的同级目录),格式如下:

    <ItemGroup>
        <Reference Include="IOM.dll">
          <HintPath>IOM.dll</HintPath>
          <SpecificVersion>False</SpecificVersion> 
        </Reference>
    </ItemGroup>
    
  6. 编辑后的HelloAras.csproj文件格式如下(看了官方文档说只要引入IOM.dll就行,但是运行过程中一直报错缺少某某dll,新增了一个后又出现缺少另一个的情况,所以尝试了直接引入bin目录下的所有dll,效果是ok的):

    <Project Sdk="Microsoft.NET.Sdk">
    ​
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
      </PropertyGroup>
    ​
      <ItemGroup>
        <Reference Include="C:\Program Files (x86)\Aras\Innovator\Innovator\Server\bin*.dll">
          <HintPath>*.dll</HintPath>
          <SpecificVersion>False</SpecificVersion>
        </Reference>
      </ItemGroup></Project>
    
  7. 编辑Program.cs文件,替换如下代码:

    using Aras.IOM;
    ​
    string serverurl = "http://localhost/InnovatorServer";
    string databasename = "InnovatorSolutions";
    string username = "admin";
    string password = "innovator";
    HttpServerConnection connection = IomFactory.CreateHttpServerConnection(serverurl, databasename, username, password);
    Item loginItem = connection.Login(); 
    Console.WriteLine("====================== Login Information ======================");
    if (loginItem.isError())
    {
        Console.WriteLine("error to login the system!");
    }
    else
    {
        Console.WriteLine("Login the system successfully!");
    }
    
  8. 通过vscode的cmd终端执行dotnet run命令,输入如下:

    D:\workspace\HelloAras>dotnet run
    ====================== Login Information ======================
    Login the system successfully!
    

本文作者:小赞(clozer)

邮箱:clozer@foxmail.com

未经授权严禁转载及使用