Hello All. First post, please be kind!
I'm just getting started with writing plugins for MicroStation, though I typically work on writing plugins for Rhino 3D. My goal is to write plugins in C# with Visual Studio 2019. I've downloaded and installed Microstation CONNECT 14 and the corresponding SDK. When I run the MicrostationDeveloperShell.bat from the SDK shortcut I get \Microsoft unexepected at this time:
\Microsoft unexepected at this time:
So I thought, ok, I'll just dig into the samples, open one up, and build it myself. Well, that didn't work either. I opened up MicroStationCONNECTSDK\examples\Elements\ManagedToolsExample, corrected the references to point to the right dlls, cleaned, rebuilt. The references still don't seem to be found.
Any advice for a beginner like myself?
Thanks in advanced and apologies for any obvious things I am overlooking on my part!
Luis Fraguada said:My goal is to write plugins in C# with Visual Studio 2019 for CONNECT U14
So far, so good!
Luis Fraguada said:When I run the MicrostationDeveloperShell.bat from the SDK shortcut
I test each release of the SDK, including that for Update 14. It all works out of the box.
Luis Fraguada said:When I run the MicrostationDeveloperShell.bat from the SDK shortcut I get \Microsoft unexepected at this time:
That looks like there's a path with spaces somewhere, that should be a quoted "path with spaces".
In the SDK shell, type SET SDK to see the environment and post the resulting FraguadaEnv.txt here...
SET SDK
FraguadaEnv.txt
SET SDK > %TMP%FraguadaEnv.txt
Regards, Jon Summers LA Solutions
SDKVSDIR=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\\ - I only have 2017 Build Tools installed, otherwise, I use 2019 SDKVSVER=2017 - same as above SHELLARGS="C:\Program Files\Bentley\MicroStation CONNECT Edition\MicroStation\" "E:\dev\MicroStationCONNECTSDK\" SHELLCMDLINE="C:\Windows\System32\cmd.exe" /x /k ""E:\dev\MicroStationCONNECTSDK\MicroStationDeveloperShell.bat" "C:\Program Files\Bentley\MicroStation CONNECT Edition\MicroStation\" "E:\dev\MicroStationCONNECTSDK\"" _SDKSEARCHDEFSREGEX="^#define.*.* ^struct.*.* ^typedef.*.* ^enum.*.* ^class.*.* ^MdlFunctionP.*.* .*_EXPORT.*.* .*_TYPEDEFS.*.*" _SDKSEARCHMSG="Would you like to continue with a web search on: Bentley Communities MicroStation Programming Forum?" _SDKSEARCHURLPOST="#serpsort=date%20desc _SDKSEARCHURLPRE="https://communities.bentley.com/search?q="
Hello Jon,Thanks for the reply. I found the announcement for the U14 SDK release which revealed I might not have all of the requirements. I installed the missing tools for Visual Studio 2019 but it had no effect on being able to build the sample.Looking at SET revealed a lot of stuff I'd rather not post, but here are the ONLY entries with quotes, or ones that stood out as interesting.
Luis Fraguada said:SDKVSDIR=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\\
SDKVSDIR=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\\
That first entry is a possible culprit. When I open my SDK window, my first relevant entry is this...
SDK=G:\PROGRA~1\Bentley\MICROS~2\SDK\
The path is modified to DOS-style short paths, with a max 8 chars per component. You may be able to modify Windows' behaviour using the fsutil behavior command.
Here's some more info about Windows, Viz Studio and the MicroStation SDK.
Hi Luis,
Luis Fraguada said:My goal is to write plugins in C# with Visual Studio 2019.
Any tool producing valid NET 4.6.2 assembly can be used to create MicroStation C# addins, so VS2019 is fine.
Luis Fraguada said:I've downloaded and installed Microstation CONNECT 14 and the corresponding SDK.
To create "normal" MicroStation C# addins, you do not need SDK at all, because the code is standard NET assembly.
The advantage of SDK is documentation of API plus some tools required for advanced topics (e.g. to compile ribbon definition to rsc and to integrate it with NET and native code).
Even when it's probably not the reason of the discussed problem, what is the full command how the shell is started?
Luis Fraguada said:I get \Microsoft unexepected at this time:
I agree with Jon there seem to be two problems:
In my opinion the latter problem is not important now (before the first one will be solved).
Luis Fraguada said:Well, that didn't work either.
All SDK examples are implemented to be built in SDk environment, when the build process is started using bmake and defined by mke file.
In my opinion it's easier to simulate SDK environment (because it's simple for NET examples) and to do only necessary minimum modifications.
Luis Fraguada said:corrected the references to point to the right dlls, cleaned, rebuilt. The references still don't seem to be found.
Do not change how references are defined. To use $(MS) variable to point to MicroStation installation is convenient and flexible way. To use absolute path, as used by default by Visual Studio, is a wrong way.
Luis Fraguada said:Any advice for a beginner like myself?
Add MS variable and points it to a folder where microstation.exe is installed (including path ending slash) and the assemblies will be found without modifying plenty of lines in csproj file.
But there is one modification you have to do in SDK NET examples: Target NET framework definition is missing in .csproj file, because defined externally when the example is compiled using bmake.
It was discussed several times already in this forum. To .csproj file, to the propery group where <FileAlignment> is defined, add a line:
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
Also, be aware SDK examples are configured to use mdlapps folder as output, which requires to start Visual Studio as administrator to allow to copy results to this folder. Alternatively you can change access rights of mdlapps folder or to use another (not so restricted) folder. But in such case, you have to modify MS_ADDINPATH accordingly.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: Luis Fraguada
Hello Jan,
I figured I was complicating the matter! With your suggestions on the MS env variable and the target framework in the csproj file, I was able to fix the references and get the project to build.
For the original issue with the MicrostationDeveloperShell.bat, I run it from the start menu:
...
But I've also run it from a command prompt, powershell, etc...
For now I will continue in my safe .net bubble and see how far I get!
Thank you!
Luis Fraguada said:I was able to fix the references and get the project to build.
Excellent!
Most of the delivered .NET examples have a batch file named openSln.bat. If you run that from the command shell it will open Viz Studio for you.
openSln.bat