1

I'm working on a windows forms project in vb.net (vs2019) where there are two versions. One for average users and another for managers. I'm using conditional compilation (#IF's) to accomplish this.

Is there a way to set the windows icon at compile time based on a compilation constant? Basically, I'd like to be able to easily identify the version based on the icon in windows explorer.

  • 1
    This sounds like an odd way to do things. Why compile two versions of your app just for different user roles? wouldn't it make more sense to set the icon at runtime based on knowledge of the current user's organisational role? I assume you can determine that based on knowing their login ID? – ADyson Jun 21 '19 at 13:27
  • You're probably right. My job isn't programming or IT so I'm probably not doing things the way a pro would. My program has no idea about who the user is or their role. Everything works fine the way I've done it though. If I can set the icon this way then great. If not ,it's not the end of the world. – user2014690 Jun 21 '19 at 13:33
  • "My program has no idea about who the user is"... you can get their windows login ID with a single line of code. You can also check their membership of Active Directory groups very easily (so you could have a manager's group and an users group), or you could assign those roles elsewhere (e.g. maybe via a database) and look them up from there. Clearly if you know the user's role you can also use it do allow/deny them access to different areas of functionality or pieces of data within the application - is that not a feature you need as well? – ADyson Jun 21 '19 at 14:09
  • It not necessarily going to to be used on the company network and I have no interest in managing a user database. Having two versions is probably actually unnecessary for any security reason. Can we please stop dwelling on this. All I want to know is if there is a way to set the icon that shows in explorer based on a compilation constant. Maybe I put too much information in my question. – user2014690 Jun 21 '19 at 14:19
  • It's good to check whether you're doing things the right way; contextual information always improves a question. Very frequently on this site people ask [X-Y questions](http://xyproblem.info/), which is revealed by the extra info they tell us. – ADyson Jun 21 '19 at 14:30
  • I haven't much experience with compiler constants (since I haven't found a use for them really, everything can be done with build configs or app.config settings generally), but it sounds like you're asking something similar to [this question](https://stackoverflow.com/questions/4660354/access-compiler-constants-in-code) - does that fit your scenario? – ADyson Jun 21 '19 at 14:31
  • Actually config transforms could be a solution for you...set the icon file in the app.config, then create build configs "admin-release" and "user-release", have a config transform for each which sets the appropriate icon file in the appSettings. When the program runs, have it set the icon filename from the settings file. See [here](https://stackoverflow.com/questions/3004210/app-config-transformation-for-projects-which-are-not-web-projects-in-visual-stud) for a starting point on config transforms. – ADyson Jun 21 '19 at 14:33
  • As a last word though, I still think you would be better off with a runtime role determination somehow. I've never, in 20 years, heard of anyone maintaining what is effectively two codebases for different user roles, instead it's always done through user management and role-based access. Maybe in the 80s it might have been a technique, but not anytime in the internet era. Is there actually more functionality which differs for the two roles than just the icon? If not, then what's the point of the distinction at all? To be clear: it's not a criticism, just trying to set a thought process going. – ADyson Jun 21 '19 at 14:36
  • Thanks for the info, I'll check it out. I appreciate your input about users/roles and the correct way of doing things and I'll keep it in mind for future projects. In this case it's just a simple tool and at this point I'm more interested is seeing if it can be done or not. I expected it to be simple but struggled to figure it out on my own. Thank you. – user2014690 Jun 21 '19 at 14:47
  • 1
    @ADyson, I can personally attest that at least the apps I worked on in the 80s did not have separate codebases for user roles. And I'm not aware of any that did do that. (Sheesh, this makes me feel old :) ). – MarkL Jun 21 '19 at 15:53
  • @MarkL well that's good to know (not that you're old, but that people have never taken that approach!). I was thinking someone _might_ have considered packaging a separate version with different feature sets for different target audiences, just to save on limited disk space or memory, or avoid having to make network calls to determine roles, or something like that. – ADyson Jun 21 '19 at 16:44
  • I looked into the config transforms and the plug-in they're talking about is pretty cool. I installed it and I'm sure I'l use it at some point. Unfortunately it doesn't work on the vb project file which seems to be where the app icon is set. It doesn't seem like there is going to be any easy way to change the icon the way I wanted. I didn't want to dwell on the reason why I was doing this and I know you guys think I'm an idiot so I'll explain a little more. – user2014690 Jun 22 '19 at 14:43
  • The only "manager" is myself, and the only features that get excluded from the user version are extra tools that I wrote to assist me in troubleshooting and testing. There's not really roles but the extra stuff wouldn't make sense to anyone else and I may still want to use it to troubleshoot any future issues. I used the #IF's to make separate versions because I thought it might make the file size a little smaller. – user2014690 Jun 22 '19 at 14:44

0 Answers0