Using Visual Studio to create scripts

Ask general questions here.
User avatar
Aracknid
Posts: 342
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Using Visual Studio to create scripts

Post by Aracknid » Tue Aug 07, 2018 4:46 pm

Years ago when I started with Ranorex and Visual Studio, I was advised to create my scripts in VS a certain way. There was information on how to do this on your web site. While reading another thread (viewtopic.php?f=13&t=12425&p=49796#p49796) I noticed they referenced this link (https://www.ranorex.com/help/latest/int ... tegration/) and so I decided to re-visit this topic and was surprised to see how different it is to create a script in Visual Studio. So I'd like to ask some questions with respect to this.

Even though I'm using Ranorex 8.2 (and having issues like mentioned in the first link above), my scripts still look much like the old way you provided as reference. I'm also coding in VB, in case this matters.

1) Does my Main function no longer require the "[STAThread"] at the front, and does leaving it there cause issues?

2) I have not added the references to all the items you mentioned, specifically ALL the plugins (I only added the ones I used) nor the Ranorex.Bootstrapper, Ranorex.Common, and Ranorex.Core.Resolver. I have had issues, which I'll look to fix using the solutions mentioned in the first link, but I was working around it by just copying all the Ranorex Bin folder to script EXE folder.

3) Every time I install a new version of Ranorex, the default folder is a folder with the version number in the path name. This seems to cause issues with references. Do you recommend we remove the version number every time to avoid issues?

Thanks,

Aracknid

User avatar
N612
Posts: 62
Joined: Mon Jul 11, 2016 4:01 pm

Re: Using Visual Studio to create scripts

Post by N612 » Fri Aug 10, 2018 4:56 am

I followed the user guide to use Ranorex in my VS project. Although the user guide does not say to add the [STAThread] attribute, Ranorex does throw a warning when running your test about it missing. Not having the [STAThread] seemed to never cause any issues for me, but I added it to my Main() method to get rid of the warning and to avoid possible issues down the road.
[2018/08/09 23:47:46.140][Warn ][Automation]: The apartment state of the current thread is not set to STA. Please make sure that all threads accessing Ranorex methods have their apartment state set to STA.

Code: Select all

[STAThread]
static void Main(string[] args)
{
    InitResolver();
    RanorexInit();
    run();
}
Also, I did add all of the mentioned libraries to avoid any issues down the road. I know many have dependencies on each other and I want to avoid any possible issues related to this by just simply adding everything recommended.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Using Visual Studio to create scripts

Post by Support Team » Tue Aug 14, 2018 9:15 pm

Hi Aracknid,
  1. The [STAThread] is required and should not be removed from your main method. The user guide does not include it because this is just a snippet, however, I have requested it be added as this can be confusing.
  2. It is a best practice for simplicity and ease to include every plugin, however, if you know what you are doing, you can get away with referencing only what you need.
  3. You can rename the folder, but you will still need to update the libraries since the version number is also referenced in the DLL itself.
    1.png
    1.png (8.56 KiB) Viewed 158 times
I hope this helps!

Cheers,
Ned
.
Image

mpbard
Posts: 2
Joined: Wed Sep 12, 2018 7:20 pm

Re: Using Visual Studio to create scripts

Post by mpbard » Wed Sep 12, 2018 7:25 pm

I'm evaluating and am trying to follow the instructions in the link mentioned above, (https://www.ranorex.com/help/latest/int ... tegration/) but nowhere on the machine is the Ranorex.Common dll that is suppoed to be included in step 4. Any idea where to find this?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Using Visual Studio to create scripts

Post by Support Team » Fri Sep 14, 2018 6:01 pm

Hi mpbard,

Upon researching your question, I have discovered Ranorex.Common is no longer needed as a reference (as it does not exist anymore). I will inform the documentation team to update this user guide page. I apologize for the confusion this may have caused and thank you for pointing this out!

Cheers,
Ned
.
Image

mpbard
Posts: 2
Joined: Wed Sep 12, 2018 7:20 pm

Re: Using Visual Studio to create scripts

Post by mpbard » Fri Sep 14, 2018 6:04 pm

Yeah, it turns out that Ranorex.Dex.Common is required instead.

Unfortunately the example posted in the original link simply does not work or even compile. Since I don't have the time to diagnose bad documentation I may need to find another solution for my needs. :(