Monday, March 8, 2021

Running prod Angular on Dev Machine

 Build your app using the prod flag. 

NG_BUILD_MANGLE=false node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng build --prod --aot


*NG_BUILD_MANGLE is used for performance troubleshooting. 

once done, go to dist directory and run npm i -g serve (if not already installed)

and then run serve -s. this will start the http server. 


Better you do performance troubleshooting in incognito mode where no chrome extension is loaded. I assumed you are using chome for performance troubleshooting :)

Wednesday, March 3, 2021

Showing network mapped drive in SQL Restore Database

 EXEC sp_configure 'show advanced options', 1;

GO

RECONFIGURE;

GO


EXEC sp_configure 'xp_cmdshell',1

GO

RECONFIGURE

GO


EXEC XP_CMDSHELL 'net use H: \\192.172.0.141\Downloads /User:username password '


You need /User if your shared drive requires authentication. Once this is done, You should be able to see H drive whle restoring the database. 


Tuesday, December 1, 2020

Set Azure App Servie Settings from Azure DevOps Pipeline

 There are instances where you need to set certain values in your Azure App Service Configuration Application Settings. You can do that through your release pipeline in Azure DevOps. 

There is a task available "Azure App Service Settings Task".

Add that task to your pipeline. Select the Azure Subscription, App Service Name, Resource Group and any slot if applicable. 

You need to set the value in the App Settings section. you need to provide the array as below. 

[
{
 "name": "himalkey1",
  "value": "himalvalueabcd",
  "slotSetting": false
},
{
 "name": "himalkey3",
  "value": "$(Variable1)",
   "slotSetting": false
}
]

In the example above, himalkey1 setting will be assigned the hard coded value. While himalkey3 will be assigned the value of Variable1. Variable1 is defined in the variable group.

Similarly, you can also set General settings and Connnection string for the Azure App. 


Sunday, July 26, 2020

A strongly-named assembly is required.

There are instances when you are try to use a nuget package in  your project and you end up with the error "A strongly-named assembly is required.". 

This is because you have given strong name to your assembly however the nuget package isn't strongly-named. Some of the nuget package release the strong-named versioned but not all. 

If you are hit with this road block, you can add a nuget package "StrongNamer". This nuget package will take care of signing the other assemblies. 

Saturday, July 25, 2020

Build Version Number in Azure DevOps

We migrated from TFS to Azure DevOps and hit with the road block to start the versioning from the same number where it left off in TFS.
Say TFS Last build number is : 1.0.0.91
then I want the next number in Azure to start with 1.0.0.92.

Here is how i cracked it.

Create a variable say V4 and set it's value to $[counter(92)].
and then you can use $(V4) in build version number. This variable is maintained per pipeline. and increment automatically any time a build is made.

There is another issue that you want to reset the 4th build number any time first 3 number changes. So you want your 4th Number relative to the first 3 version numbers.
For example,
your current number is 1.0.0.92
and you increment third number,
1.0.1.X, you don't want your X to be 93 next. you want it to start from 0. and same rule applies anytime you change other build number

Here is how you can change it.
Create 4 variables in build pipeline.
V1 => 1
V2 => 0
V3 => 0
V4 => $[counter(format('{0}.{1}.{2}',variables['V1'],variables['V2'],variables['V3']),0)]

Here V4 is defined as related to V1, V2 and V3. The value of the counter (V4) will be maintained per value of V1, V2 & V3 per pipeline. any time the the value of any V1, V2 & V3 changes, V4 will reset the counter to zero.

This will fix your problem of managing the build number for your builds.


Monday, May 25, 2020

Code Coverage for Azure DevOps



  1. In your Visual Studio solution, add a unit test project (end of name with Tests).
  2. Reference the Nuget package coverlet.msbuild which will be used as an extension of the dotnet test command used later.
dotnet test --configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=./TestResults/Coverage/

reportgenerator -reports:.\TestResults\Coverage\coverage.cobertura.xml -targetdir:.\CodeCoverage -reporttypes:HtmlInline_AzurePipelines

  1. In Azure DevOps Pipeline Build, add a task .NET Core to perform unit tests and collect data on code coverage (via coverlet). This task will generate a coverage.cobertura.xml file in your test project folder, in Cobertura format which is supported by Azure DevOps.
    • Commande : Test
    • Path to projet(s) : **/*[Tt]ests/*.csproj
    • Arguments : --configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=./TestResults/Coverage/ /p:CoverletOutputFormat=cobertura
    • Publish test results and code coverage : checked
  2. Via the Marketplace, add the extension[ReportGenerator] (https://marketplace.visualstudio.com/items?itemName=Palmmedia.reportgenerator) (from Palmmedia) and this task in your Pipeline:
    • Reports : **/coverage.cobertura.xml
    • Target directory : CoverageReport
    • Report types: HtmlInline_AzurePipelines;Cobertura
    This task will generate an HTML report of the coverage code (supported by Azure), in the /CoverageReport folder.
  3. Add a task Publish code coverage results to publish the HTML report in a Coverage tab of the Build Summary.
    • Code coverage tool : Cobertura
    • Summary file : **/coverage.cobertura.xml
    • Report dyrectory : CoverageReport

Exclude Any assembly:
reportgenerator -assemblyfilters:-BuildLibrary -reports:.\TestResults\Coverage\coverage.cobertura.xml -targetdir:.\CodeCoverage -reporttypes:HtmlInline_AzurePipelines

+ to include and - to exclude and Name of the assembly without extension.
File Filter:

reportgenerator -filefilters:-*Reference.cs* -reports:.\TestResults\Coverage\coverage.cobertura.xml -targetdir:.\CodeCoverage -reporttypes:HtmlInline_AzurePipelines

Ref:

Azure DevOps and the Code Coverage


Wednesday, May 6, 2020

How to set ArrAffinity cookie SameSite attribute to None for Azure App Service with web.config


<system.webServer>
  <rewrite>
    <outboundRules>
      <rule name="Add SameSite Cookie Flag to ArrAffinity cookie" enabled="true">
        <match serverVariable="RESPONSE_Set_Cookie" pattern=".*" />
        <!--pattern="ARRAffinity=.*\/;.*"-->
        <conditions>
          <!-- <add input="{R:0}" pattern="SameSite=(Lax|Strict|None)" ignoreCase="true" negate="true" /> -->
          <add input="{R:0}" pattern="ARRAffinity=(.*)" ignoreCase="true" negate="true" />
          <add input="{HTTP_USER_AGENT}" pattern="Macintosh; Intel Mac OS X 10_14.+Version/.*Safari" ignoreCase="true" negate="true" />
          <add input="{HTTP_USER_AGENT}" pattern="CPU iPhone OS 12" ignoreCase="true" negate="true" />
          <add input="{HTTP_USER_AGENT}" pattern="iPad; CPU OS 12" ignoreCase="true" negate="true" />
        </conditions>
        <action type="Rewrite" value="{HTTP_COOKIE};Path=/;HttpOnly;SameSite=None;secure" />
      </rule>
    </outboundRules>
  </rewrite>
</system.webServer>



Credit to Clover Zhang @Microsoft.