Page 1 of 1

How to remove readonly mode from .cs file after recording

Posted: Tue Feb 10, 2015 11:06 am
by smohanty78
Hi
After recording I would like to do some changes directly to .cs file.
Could you please tell me how to write to the file? as it comes as read-only file
Regards,
Sangita

Re: How to remove readonly mode from .cs file after recording

Posted: Tue Feb 10, 2015 2:55 pm
by krstcs
***Do NOT change the .cs files that are locked.***

They are locked because they are generated by Ranorex and should not be manipulated as it could cause problems.

Also, any changes made to the file will be destroyed when the file is re-written by Ranorex.




If you need to write code-behind for a Recording module, you should use the *.UserCode.cs file. Add a UserCode action to the action table and then add a method to the UserCode file.

Re: How to remove readonly mode from .cs file after recording

Posted: Tue Feb 10, 2015 2:57 pm
by andrefelipe
Hello smohanty78,

As far as I know, Recorded modules, are generated by Ranorex and they cannot be changed.
But they are all partial class, with a UserCode part, where you can add your own methods and call them in the recording module.

Here we go:

Find the usercode part
Image

Open and add what you want
Image

Add a usercode activity, and call your method.
Image

The other option, is to write an entire usercode module, but I don't think that's what you want.

Regards,
André Felipe

Re: How to remove readonly mode from .cs file after recording

Posted: Tue Mar 31, 2015 1:29 pm
by smohanty78
Thanks a lot for the nice explanation.

Re: How to remove readonly mode from .cs file after recording

Posted: Wed Apr 27, 2016 12:16 pm
by conradb
I just randomly found myself in the same situation:
I added two actions to a recording, and the disabled a different action, but every time I ran the test it was clearly running the old/origional test code. I restarted Ranorex and rebuilt the solution 3 times, problem persisted. I then saw that Ranorex "thinks" the generated C# file is read-only, and the file was not re-generating.
1. I worked around it by just deleting the generated file.
2. Why did the build task not error? I assume the generated file .cs is not a dependency of the recording .rxrec - or the computer time was out and thus the recording was not newer according to the make rules?

I am using perforce version control, which apparently is not compatible, and we are checking generated files into the version control, and then checking all files out whenever we do any work.

Next time I'll just delete the generated file as a first thing to try :-)

Re: How to remove readonly mode from .cs file after recording

Posted: Wed Apr 27, 2016 12:29 pm
by odklizec
Hi,

I don't know Perforce version control system, but I guess the read-only is caused by Perforce itself? I remember a similar issue caused by TFS, where server-based workspace caused read-only flag to local files. Once the workspace has been switched to 'local', the read-only problem was fixed. So I would suggest to search/discuss this behavior with Perforce support?

Re: How to remove readonly mode from .cs file after recording

Posted: Wed Apr 27, 2016 2:30 pm
by conradb
It's my "future" intention to delete all generated files and somehow get our build script to regenerate them in future via msbuild. This would fit with the pattern of not ever storing any files that one can easily generate.

I'm pretty sure it was finger problems on my part that got me here, since I have a script that makes all files read-write after I sync down the code. Thanks once again for the quick responses.

Re: How to remove readonly mode from .cs file after recording

Posted: Wed Apr 27, 2016 2:33 pm
by krstcs
Yeah, I agree with Pavel. Sounds like your version control system set the file to read-only.

Ranorex doesn't mark the .cs file read-only in the file-system, only in Ranorex Studio. You can make manual changes to those files all day long in another text editor and Ranorex won't care, you just can't do it through Studio itself.

Re: How to remove readonly mode from .cs file after recording

Posted: Fri Apr 29, 2016 2:37 pm
by conradb
When I delete all the generated files (files that contained the warning banner ) and then click "clean", then click "build solution" in studio it creates a swathe of warnings for each missing file.

Is deleting all files containing 'DO NOT MODIFY THIS FILE!' the correct strategy for force a project to upgrade to a newer version of studio?

Re: How to remove readonly mode from .cs file after recording

Posted: Fri Apr 29, 2016 3:25 pm
by krstcs
No, Ranorex automatically updates the .cs files every time you build the projects or solution. You should not delete the files as Ranorex only generates the file when the module is first created, it just regenerates the contents when you change the rxrec file or when you recompile.

Re: How to remove readonly mode from .cs file after recording

Posted: Tue May 03, 2016 12:30 pm
by conradb
My intention with deleting all generated or generateable files was to be able to remove them from version control, and then to get them to regenerate in the MSBuild script. I hoped it slightly reduces number of files to check in when doing an average test change, but most fixes seem to touch quite a few files, so eliminating generated files is not a massive win.

So yes, you can delete them, but it's not really useful to do so in the end.