Windows shell commands

In Microsoft Windows you are able to access some special folders and start some special application from Run… and then type a magic command.

One of these folders is %appsfolder% with a list of installed applications. From this folder you are able to create shortcuts etc. This folder can be accessed using the Windows Run command box and typing “shell:appsfolder”.

When you want to open the folder or run another command without first clicking Windows, Run: You are also able to execute the command from a command prompt using “start” and then the magic words you have to type in the run command box.

for example typing “start shell:appsfolder”

Allow remote access to IISExpress for development in VS

When you want to test your website and check it remote you see the error:

Bad Request – Invalid Hostname


HTTP Error 400. The request hostname is invalid.

First thing to do is to find the correct applicationhost.config file. This file can be found in

the solution directory under .vs/<Solution name>/config. This file contains an entry under the tag <sites> for the site with the config that is applied in IISExpress.

This enables binding for the IIS:

    <bindings>
      <binding protocol="http" bindingInformation="*:29136:localhost" />
      <binding protocol="https" bindingInformation="*:44343:localhost" />
    </bindings>

Above configuration only allows localhost to access the IISSExpress site.

Change it to:
        <bindings>
          <binding protocol="http" bindingInformation=":29136:" />
          <binding protocol="https" bindingInformation=":44343:" />
        </bindings>
to allow remote machines to access the site.

adb server’s $ADB_VENDOR_KEYS is not set

While debugging an Android application I wanted to connect to a new device. I factory reset the device and wanted to deploy the application with adb (Android Debug Bridge).

Response from adb after run android –livereload was:

adb.exe: device unauthorized.
This adb server’s $ADB_VENDOR_KEYS is not set
Try ‘adb kill-server’ if that seems wrong.
Otherwise check for a confirmation dialog on your device.

My colleague had the same experience earlier and didn’t know how to solve this. The first entries in google didn’t provide a correct solution.

I tried several first like removing the .android folder from my profile. All effort was unsuccessful.

The solution simply was to allow USB connection on the device via USB debugging in developer options on the Android Device.

Some of these settings are hidden or managed by your organization

At the office I had a problem with my developer PC. It was running Windows 10 and for some Visual Studio projects (UWP) etc. I had to set my machine to Developer Mode.

This setting can normally be set in Windows Settings, Update & Security, For Developers…

However….

On my machine this window stated that some of these settings are hidden or managed by your organization.

So I called my organization but they were unable to help me out. No one knew the cause of this message. No policy setting was set, I was administrator on the machine etc…

Call closed…

Problem not solved…

I needed this fixed so I gave it my best try… Maybe google could help me out. After a few searches I got the idea the message could erroneously be set by Windows, not because of company policies. I looks like some combination of settings and Windows 10 updates can have this situation as a result.

Walking through various forums with all kind of solutions, there was one simple solution that helped me out…

Remove all settings in the registry key except for one.

Make sure the key Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Appx looks like this:

In my case it also contained the key AllowDevelopmentWithoutDevLicence set to false. I completely removed that key and set AllowAllThrustedApps to true. Rebooted my machine.

Problem solved, case closed.

Windows 10 client blocking access to server open file share with guest access

A new policy implementation on a new Windows 10 machine can cause Windows 10 to report that certain shares are inaccessable due to policy settings.

The solution is to change the Local Group Policy with gpedit.msc:

Navigate to Computer Configuration -> Administrative Templates -> Network -> Lanman Workstation and select the Enable insecure guest logons as shown in the below screenshot.

Create a certificate for package signing AND deploy a MSIX package

I wanted my application to be available via a MSIX installer. This new MSIX installer supports all type of Windows applications including Win32, WPF, WinForm and UWP.

I struggled a few days to get the certificate right so that is why I published this article. This article goes through the process of creating a certificate and adding this to the app installer package.

First you need to add a new project to your solution. The solution type is called Windows Application Packaging Project. This is done by right clicking the solution and go to Add > New Project…

Determine the subject of your packaged app
To use a certificate to sign your app package, the “Subject” in the certificate must match the “Publisher” section in your app’s manifest.

For example, the “Identity” section in your app’s AppxManifest.xml file should look something like this:

<Identity
    Name="12345678-1234-1234-1234-1234567890ab"
    Publisher="CN=Contoso Software, O=Contoso Corporation, C=US"
    Version="1.0.2.0" />

The “Publisher”, in this case, is “CN=Contoso Software, O=Contoso Corporation, C=US” which needs to be used for creating your certificate.

Then run the following commands in an elevated PowerShell prompt:

  1. PS C:\WINDOWS\system32> New-SelfSignedCertificate -Type Custom -Subject “CN=Contoso Software, O=Contoso Corporation, C=US” -KeyUsage DigitalSignature -FriendlyName “Certificate for Installing MSIX/Appx from Contoso Software” -CertStoreLocation “Cert:\CurrentUser\My” -TextExtension @(“2.5.29.37={text}1.3.6.1.5.5.7.3.3”, “2.5.29.19={text}”)

    PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\My

    Thumbprint Subject
    ———- ——-
    2B046FBC587DD867989D6165570B4C144F557FCE CN=Contoso Software, O=Contoso Corporation, C=US
  2. PS C:\WINDOWS\system32>Set-Location Cert:\CurrentUser\My
  3. PS Cert:\CurrentUser\My> $password = ConvertTo-SecureString -String mypassword -Force -AsPlainText
  4. PS Cert:\CurrentUser\My> Export-PfxCertificate -cert “2B046FBC587DD867989D6165570B4C144F557FCE” -FilePath c:\Contoso.Software.pfx -Password $password

    Directory: C:\

    Mode LastWriteTime Length Name
    —- ————- —— —-
    -a—- 7-9-2020 08:42 2756 Contoso.Software.pfx

Then add the certificate to the package installer in Visual Studio:

Next publish the app:

Import the certificate if it is not already installed

Start Manage computer certificates to import the certificate to the computer(s) to which you wish the app to deploy

If it is not present in Thrusted People, import the certificate

Next publish the app

And double click the PackagingProject.appinstaller from the installer folder

Azure click once publish for test and production CI/CD

Change config and sign a click once deployment for test in an Azure build application:

I have the following release pipeline in Azure:

Continuous Integration pipeline that will build for every check in on master branch. This build will trigger a Continuous Delivery pipeline that will deploy the release for the click once application to test. The same installation wil be deployed to production after approval in test on this pipeline.

I want the same build that I tested to go to production. The click once is compiled for release. The app.config I have in source is the production version. So once installed the app will default be configured to connect to production datasources.

For test however I want the app.config to be replaced with a app.config.debug version. This is a app.config that contains the test and debug datasources.

After putting this config file in the deployment the signature for the click once is no longer valid. I resigned the click once manifest for the changed config with a tool from Microsoft .NET SDK.

I used the mage.exe (from .NET framework Tools). Path for my installation: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\mage.exe.

I added 3 files to the source directory:

mage.exe
app.config.debug
ACertificateFile.pfx. This pfx is the same I used in the project to sign the manifest file.

After adding these 3 files to the source folder I added a copy step in the build pipeline to add these files to the app.publish folder:

And a script to update the app.config and resign the manifest has to be executed before copying the files to the local deployment server.

@echo on
for /f “delims=” %%F in (‘dir “$(system.defaultworkingdirectory)_Bla.WPF.BLA-.NET Desktop-CI\$(System.TeamProject)-$(Build.BuildNumber)\Application Files” /B /AD’) do set deployDir=%%F
set “to=$(system.defaultworkingdirectory)_Bla.WPF.BLA-.NET Desktop-CI\$(System.TeamProject)-$(Build.BuildNumber)\Application Files\%DeployDir%”
set “from=$(system.defaultworkingdirectory)_Bla.WPF.BLA-.NET Desktop-CI\$(System.TeamProject)-$(Build.BuildNumber)”

copy /Y “%from%\App.config.debug” “%to%\BLA.exe.config.deploy”

ren “%to%*.deploy” *.
“%from%\mage” -sign “%to%\BLA.exe.manifest” -CertFile “%from%\ACertificateFile.pfx”
“%from%\mage” -update “%to%\BLA.exe.manifest” -CertFile “%from%\ACertificateFile.pfx”
“%from%\mage” -update “%from%\BLA.application” -appmanifest “%to%\BLA.exe.manifest” -CertFile “%from%\ACertificateFile.pfx”

ren “%to%*.*” *.*.deploy
ren “%to%*.manifest.deploy” *.
del “%from%\mage.exe”
del “%from%\App.config.debug”
del “%from%\ACertificateFile.pfx”

Important steps to publish a click once app using Azure

Publish in Azure pipeline:

step 1 Build solution with parameter /target:publish

YAML: #Your build pipeline references an undefined variable named ‘Parameters.solution’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972

#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

steps:

– task: VSBuild@1

  displayName: ‘Build solution **\*.sln’

  inputs:

    solution: ‘$(Parameters.solution)’

    msbuildArgs: ‘/target:publish’

    platform: ‘$(BuildPlatform)’

    configuration: ‘$(BuildConfiguration)’

Step 2: Copy artifact files to publish folder

NuGet pack with include referenced projects

Yesterday I wanted to build a NuGet package with a dll that references a project in the same solution. The referenced project however was not added to the installation package when I packed a new Nuget package.

I searched the internet and found some remarks about adding a parameter includereferencedprojects.

Then I came to my pack command in Azure and saw that the parameter was not in the Nuget pack task.

The YAML i had:

At first I didn’t know how to add the includereferencedprojects parameter. I then changed the “automatic package versioning” in “pack options”. I set it to “Off” and an extra checkbox was presented:

I checked the box:

And set the versioning back to the previous value.

Now my YAML included the includereferencedprojects parameter.

After I started a new build with this pipeline, the referenced project dll’s were added to my package.

How to select duplicate values in a SQL table

First make a selection of duplicate values using count:
SELECT
col1, COUNT(col1) AS CountOf
FROM test
GROUP BY col1
HAVING COUNT(col1)>1

Then join this selection with the table on table keys:

select [key],a.col1 from
test a
inner join (SELECT
col1, COUNT(col1) AS CountOf
FROM test
GROUP BY col1
HAVING COUNT(col1)>1) b on a.col1 = b.col1