Class library assemblies used by Windows Services written in C# - windows-services

If I write a C# class called Foo and that is compiled into an assembly named FooLib.dll. Then, I write a Windows Service in C# that references FooLib.dll. When I deploy my Windows Service using InstallUtil.exe:
a) do I have to explicitly tell it to reference my FooLib.dll?
b) where does FooLib.dll get deployed if I mean to deploy it as a private assembly and not in the GAC?

You can just place the FooLib.dll in your Windows service target directory and that should do.
For example, If your service named "MyService" is pointing to c:\folder1\MyService.exe, put the FooLib.dll in c:\folder1.
Ideally, you put the exe which is going to be the windows service and all its dependecies in one "deployment" folder and then run installutil on <PathToTheDeploymentFolder>\MyService.exe.

Related

How could IDE index the library folder in the docker container?

We usually use an IDE to develop programs.
However, the IDE is not smart enough to travel the library folder in the docker container.
So navigation to the source (for example, in PyCharm, you want to see the code in the installed third-party package) is usually not available. The IDE simply said "No module named xxxx".
How could this be fixed?

.NET Core Application and System.DirectoryServices in Docker container

I'm trying to put a .NET Core 3.1 application listing users in an AD group into a .NET Core Runtime Docker container.
Accessing the AD is being done with the help of a DirectorySearcher from the System.DirectoryServices namespace.
Out of the box, .NET Core doesn't support this namespace, but by adding the package System.DirectoryServices (dotnet add package System.DirectoryServices) installed the required assemblies and the application runs fine on a Win10 machine.
Trying to let the app run in a Linux .Net Core Runtime container throws an exception because DirectoryServices doesn't support this platform.
So I tried using a Windows-based container (tag 3.1.8-nanoserver-2004 to be precise), but then the DirectorySearcher's FindAll() throws the exception
System.DllNotFoundException: Unable to load DLL 'activeds.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
I've even tried copying the DLL from my host machine into the application's bin directory in the container, but to no avail.
Anyone got an idea what to do to access AD/LDAP from a container?
Since I could not get a Windows Server container to add the Active Directory feature for the life of me, I decided to switch to something different and found LdapForNet
While this works nicely on the dev machine, I also had a hard time finding a way to call the required Bind() to our domain controller from inside a container.
But after half a day of trial and error I found that LdapAuthType.Negotiate worked, but only if I gave the Realm as well:
using (var conn = new LdapConnection()){
conn.Connect(new Uri("LDAP://the.domain.controller"));
conn.Bind(LdapForNet.Native.Native.LdapAuthType.Negotiate,
new LdapCredential {
Realm = "DC=thedomain,DC=com",
UserName = "The user to authenticate",
Password = "Plain text password"
}
);
}
Hope this helps others trying to get LDAP queries running inside a container.
Next stop: Trying the same inside a Linux container.
DirectoryServices will not currently work in Nano Server because the required dependencies are not available. You'll need to use a Windows Server Core image instead. There are not official .NET Core images available for Windows Server Core. (At least not yet. When .NET 5.0 ships, Windows Server Core images will be available for it. See GitHub issue for that proposal.)
You'll need to define your own Dockerfile that uses Windows Server Core as a base image and installs .NET Core in it. There is guidance on how to do this here.
Related links:
Using System.DirectoryServices on a Windows container with ASP.NET Core returns an error
DirectoryServices deployement on nano serve Unable to load activeds.dll

WebDeploy package contains personal folder path

When I use the Web Deploy Package publish method to publish a ASP.NET MVC website in Visual Studio 2019, the package contains multiple references to my computer and personal folder paths.
For example, the systemInfo.xml file contains:
<systemInfo osVersion="6.3" winDir="C:\windows" machineName="[***MYCOMUTERNAME***]" processorArchitecture="x86" msdeployVersion="1.0" buildVersion="7.1.2606.1250">
And the *.sourceManifest.xml file contains:
<IisApp path="C:\Users\[***MYUSERNAME***]\Source\Repos\myproject\obj\x64\Release\Package\PackageTmp" />
The package still works, but if I want to use this package to distribute the software, how can I build it so that it does not contain personal information?
Web deploy packag always contain the physical path of your project and machine name automatically no matter you generate package from VS or webdeploy. So if you need to hide [MYUSERNAME], please move your project to another path which doesn't contain username.
web deploy package can be pushed remotely so you don't have to worry about the machine name.https://learn.microsoft.com/en-us/previous-versions/aspnet/ff356104(v%3Dvs.110). If you don't want to expose the machine name, you can edit system.info manually.

Finding dependencies of containerized windows apps

I would like to find out the missing dll needed for my exe file that is stored in the container. Found out https://stefanscherer.github.io/find-dependencies-in-windows-containers/ method but it requires installation of virtual machine. Is it possible to install dependency walker into the container using docker file to find the missing dll? I am using windowservercore as base image.

How to bundle Electron application and windows service together?

I am very new with electron application. I need some help with election installation.
I have an Electron desktop application and a windows service.
I can start and stop my pre installed services by using sudo-prompt package.
I am creating windows installer by using electron-winstaller package.
But I want to bundle my windows service along with my electron application. My requirement is when I install my electron package then it should install my service also, when I uninstall my package then that service should be uninstalled.
Please help me out. Any clue, Any suggestions will be appreciated.
If you think this should be achieved with something else then please do suggest me.
Electron's windows installer packager strikes me a specific case tool that would likely hit limitations in scenarios like this. I would use a general case tool instead such as the Free and Open Source Windows Installer XML Toolset aka WiX. I would also use with that another FOSS application called Industrial Strength Windows Installer XML aka IsWiX.
WiX allows you to describe and build MSI databases using an XML/XSD domain specific language. It supports MSBuild for easy integration with your CI/CD pipeline. IsWiX* is a set of project templates and graphical designers that provide an opinionated project structuring (scaffolding) and greatly speeds up the learning curve and implementation. For example, this installer you describe could be done without writing a single line of XML.
For more information see: https://github.com/iswix-llc/iswix-tutorials
The desktop-application and windows-service tutorials should** show you everything you need to know to author this installer. Basically follow the desktop-application all the way through and then skip to the final portion of the windows-service tutorial where you define the windows service.
I'm the maintainer of IsWiX
** This assumes your service exe is a proper Windows service that interfaces with the windows service control manager. If it's really just a console app that runs as a service you will need to include a program such as srvany.exe. This will require one line of hand crafted XML to extended the service definition in the registry with the proper command line value to be passed to your exe. An example can be found here: Wix installer to replace INSTSRV and SRVANY for user defined service installation

Resources