Posts

Create Multiple Assemblies from a Single .NET Framework Source File

Image
This article is a continuation of Set .NET Assembly File Version Info in Source Code . Here, we explore the use of Conditional Compilation to reinforce coherent versioning across multiple assemblies. By the way, with the help of compiler symbols and conditional statements, we can delineate the assemblies' codes from each other and pack them in a single source file. These code blocks will share the same header from where we initialize their version attributes. So, when there is a need to change the version or a piece of information, we will change it from one file. This solution is just an alternative to Visual Studio for project management, and I prefer it for simple use-case projects. Here is a simple example. We have two source files, which I will compile into a library and an application, respectively. Library.Launcher.cs using System; using System.Reflection; [assembly: AssemblyProduct("My Product")] [assembly: AssemblyInformationalVersion("0.4.0.12"

Set .NET Assembly File Version Info in Source Code

Image
A file version information object looks like this in PowerShell (the list of properties is narrowed down to the ones set by the assembly attributes in this article): PowerShell PS> Get-Item MarkdownToHtml.Shortcut.Launcher.dll | Select-Object -ExpandProperty VersionInfo | Format-List FileDescription,ProductName,Comments,CompanyName,FileVersion,ProductVersion,Language,LegalCopyright,LegalTrademarks FileDescription : MarkdownToHtml Shortcut Launcher Library ProductName : MarkdownToHtml Shortcut Comments : Library of Launcher type. CompanyName : sangafabrice FileVersion : 0.4.0.12 ProductVersion : 0.4.0.12 Language : French (Cameroon) LegalCopyright : © 2024 sangafabrice LegalTrademarks : FromTheTechLab™ To set version information for .NET assemblies, you can insert assembly-level attributes in the source code header (not mandatory, but good practice). The Details tab of an assembly Properties box displays the values ​​for a few attributes,

Hide Console Window with .NET Framework

Image
This article is a continuation of Hide Console Window with JScript/WSH . Here, we use an assembly instead of a script to accomplish the same task. However, it remains simple to set thanks to the compilers available with the .NET Framework 4.0 : csc.exe , vbc.exe and jsc.exe , which compile C# , VB.NET and JScript.NET (different from JScript/WSH), respectively. They allow us to build applications for Windows, which installation includes them by default. I start by inspecting the .NET types involved in the solution. Types inspection with Windows PowerShell When coding in C# 5.0 , Visual Basic 2012 , we should remember that a few constructs of the latest versions of these programming languages are not available. So, I prefer inspecting objects and methods using PowerShell v5 when preparing for programming for the .NET Framework. The types used are defined in the System.Diagnostics namespace. I declare it first to avoid writing the type full names later on. PowerShell PS

Change Console Icon at Runtime Using Shortcuts

Image
Using .lnk shortcuts can make automation scripts look like third-party applications. Instead of displaying the proprietary icon of a script runner like PowerShell, it shows the shortcut icon that launched it on the title bar of the console window and the taskbar. Here is an illustration of the situation described. In a PowerShell session, we create a powershell.lnk file with a custom icon that is located in the working directory ( PWD ): PowerShell PS> $shell = New-Object -ComObject WScript.Shell PS> $shortcut = $shell.CreateShortcut('.\powershell.lnk') PS> $shortcut.TargetPath = 'powershell.exe' PS> $shortcut.Arguments = '-WindowStyle Maximized' PS> $shortcut.IconLocation = "$PWD\CustomIcon.ico" PS> $shortcut.Save() To read more about the method CreateShortcut() , visit the Microsoft Learn website. Then, we open the saved shortcut link. PowerShell PS> .\powershell.lnk In the image above, the icon displayed on t

Hide Console Window with JScript/WSH

Image
Starting a PowerShell session or running the Command Prompt from the Task Scheduler or a context menu shortcut brings up a window that notifies one of the execution of those programs. It might be a desirable behavior, but it is particularly odd in the case of shortcuts. Another reason for hiding console windows is to avoid an unintended clicking on the console, which pauses the session execution and prefixes the window title with the word Select . Such a mistake may cause side effects on processes waiting for the exit of the console or watching its window title attribute as illustrated in the video below. It is possible to set the window style of PowerShell console window from the command line with the parameter -WindowStyle Hidden ; still, the window flashes before disappearing. Windows Script Host Shell COM The Windows Script Host Shell COM provides an API to interact with the Windows Shell or a more specific sub-component; the Command Prompt. The method Run executes

Mind Blogging: ConvertFrom-Markdown to HTML

Image
HTML may be the web standard format, but I turn to Markdown to markup my posts. As I am starting this adventure in blogging, I have traded off complexity and detailed structuring for more fast-paced generated content. When creating a new article, I tend to focus more on the textual organisation of my ideas, and I delay the visual layout design to a later stage of the workflow. To transition between the two phases, each necessitating a different markup language, I equip myself with a Windows context menu shortcut that helps to convert my Markdown documentation into HTML articles. I configure the feature shortcut with the MarkdownToHtmlShortcut PowerShell module. In addition to the target script, the module packages functions for adding and removing the shortcut to and from the right-click context menu of .md files. Convert To HTML shortcut The excerpts in this article do not display the entire code of the script files or functions discussed, but they form the basis of the pr

Start a Program on the Remote Active Desktop with PowerShell

Image
The goal is to run a command to open a program window like Notepad or Photoshop on a remote computer desktop using PowerShell Remoting . This powerful feature allows us to establish remote sessions, but by default, it only allows executing scripts on the target machine as services . So, the established session is disconnected and not visible to the user watching the remote computer screen. The graphic interfaces of programs started in the session are not visible either. However, we are set in this tutorial to show how to leverage the Task Scheduler to open an application window on a remote desktop and make it visible to the user's eyes. 1. The context In this section, we are opening a program from a PowerShell session, for instance, Notepad. We describe why it is not visible on the remote desktop by default. The commands below open an interactive session with the remote computer identified on the network as inonw-svr . You will notice the chevron arrow pointing to the properti