VSCode CLI commands for C# Project

April 20, 2021 Leave a comment

To see a list of all installed templates

dotnet new --list or dotnet new -l 

.NET Core CLI command for project creation:

@ for console
dotnet new console -n microsoft.botsay -f net5.0
@ for empty webapp
dotnet new web -n microsoft.web -f netcoreapp3.1

syntax: dotnet new <TEMPLATE> -n application_name -f framework_version

net5.0 => .NET applications
netcoreapp3.1 => .NET CORE applications

.NET CORE command to create Solution file:

dotnet new sln -n mysolution   ==> creates solution file with name mysolution
dotnet new console -o myapp   ==> creates new console app
dotnet new classlib -o mylib1   ==> creates new classlib app 
dotnet new classlib -o mylib2   ==> creates new classlib app
dotnet sln mysolution.sln add myapp\myapp.csproj ==> Adds console app to the solution file

==> Adds classlib to the solution file
dotnet sln mysolution.sln add mylib1\mylib1.csproj --solution-folder mylibs

==> Adds classlib to the solution
dotnet sln mysolution.sln add mylib2\mylib2.csproj --solution-folder mylibs

Reference: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-sln

Create Nuget package from exe app

1. Open the console app .csproj file and add three new XML nodes to the end of the <PropertyGroup> node:

    <ToolCommandName> is an optional element that specifies the command that will invoke the tool after it's installed. If this element isn't provided, the command name for the tool is the project file name without the .csproj extension.

    <PackageOutputPath> is an optional element that determines where the NuGet package will be produced. The NuGet package is what the .NET CLI uses to install your tool.
2. Create a NuGet package by running the dotnet pack command:
    dotnet pack

$$ Reference Article: https://docs.microsoft.com/en-us/dotnet/core/tools/global-tools-how-to-create

List the projects in a solution:

dotnet sln todo.sln list

Add a C# project to a solution:

dotnet sln add todo-app/todo-app.csproj

Remove a C# project from a solution:

dotnet sln remove todo-app/todo-app.csproj

Add multiple C# projects to the root of a solution:

dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj --in-root

Add multiple C# projects to a solution:

dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj

Remove multiple C# projects from a solution:

dotnet sln todo.sln remove todo-app/todo-app.csproj back-end/back-end.csproj

Build .NET project:

Reference: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build

# Build a project and its dependencies:
    dotnet build

# Build a project and its dependencies using Release configuration:
    dotnet build --configuration Release

# Build a project and its dependencies for a specific runtime (in this example, Ubuntu 18.04):
    dotnet build --runtime ubuntu.18.04-x64

# Build the project and use the specified NuGet package source during the restore operation:
    dotnet build --source c:\packages\mypackages

# Build the project and set version as a build parameter using the -p MSBuild option:
    dotnet build -p:Version=

Add assembly reference to the project:

Reference: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-add-reference#:~:text=h%7C%2D%2Dhelp-,Description,added%20to%20the%20project%20file.
* Syntax:
dotnet add [<PROJECT>] reference [-f|--framework <FRAMEWORK>] [--interactive] <PROJECT_REFERENCES>

dotnet add reference -h|--help ==> for help

Add a project reference:
dotnet add app/app.csproj reference lib/lib.csproj

Add multiple project references to the project in the current directory:
dotnet add reference lib1/lib1.csproj lib2/lib2.csproj

Remove assembly reference from the project:

Reference: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-remove-reference
dotnet remove [<PROJECT>] reference [-f|--framework <FRAMEWORK>] <PROJECT_REFERENCES>

dotnet remove reference -h|--help

Remove a project reference from the specified project:

dotnet remove app/app.csproj reference lib/lib.csproj

Remove multiple project references from the project in the current directory:

dotnet remove reference lib1/lib1.csproj lib2/lib2.csproj

Open .NET core project in VS Code:

1. Navigate to project folder 
2. In address bar type cmd + enter key ==> open cmd prompt

CLI command for Generating User Secrets

dotnet user-secrets set "CertPassword" "pa55w0rd!"
# In VS Code: Install InsertGUID lib/package to generate the GUID
# Insert this GUID in the <projectname>.csproj file as below
# Run the CLI command 
    dotnet user-secrets set "CertPassword" "pa55w0rd!"
    here: CertPassword => "Kestrel:Certificates:Development:Password"
    e.g dotnet user-secrets set "Movies:ServiceApiKey" "12345"
        The colon denotes that Movies is an object literal with a ServiceApiKey property.

    or CertPassword => can be key whose value is the password we specify
# UserSecrets are stored at path on local machine: 
# These UserSecrets is a .json extension file

Release build configuration

dotnet run --configuration Release

Categories: General

How to set Multiple Startup Projects in Visual Studio 2015

February 5, 2018 Leave a comment

To set multiple startup projects
In the Solution Explorer, select the solution (the very top node). Right-click the node to get the context menu.

Select Properties. The Solution Property Pages dialog box opens.

Expand the Common Properties node, and click Startup Project.

Click Multiple Startup Projects and set the appropriate actions.

Simple as you can think 🙂

Categories: General, Visual Studio

Building Windows Service using visual studio-C#

December 5, 2013 Leave a comment

Hi All,
Here I come back again and this time with Windows Service and related things. 🙂
In my carrier I had came across this stuff several times and always thought of writing something on this but unfortunately it always got skipped and went out side of the bucket.
Anyways here I start with:
Windows Service is an windows utility which keeps running behind the screens silently but sometime violently. As this utility runs behind the screen hence its obvious this has nothing to do with the UI, forms or any other cosmetic works.

  • So, how to build it?

Well building an win.service basically one needs to have 2 things:
1. Windows Service Class: Accommodates the code for which the service is written
2. Installer Class: For installing the service

Open visual studio 2010 (the steps are almost same since from ages!) & create an project , while doing so choose the WindowsService Template under the winodws header of your intended programming language.
More details can be retrieved from MSDN, CodeProject

Installing / Unistalling Window Service

      1. Windows service can be installed by firing installutil from the visual studio command prompt – Details on MSDN
      2. Alternative for the installutil is to make use of System.Configuration.Install assembly

using System;
using System.Collections.Generic;
using System.ServiceProcess;
using System.Configuration.Install;
using System.Reflection;
namespace WinService
static class Program
static void Main(string[] args)
if (Environment.UserInteractive)
string parameter = string.Concat(args);
switch (parameter)
case "--install":
ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
case "--uninstall":
ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
ServiceBase[] servicesToRun = new ServiceBase[]
new Service11()
#region Commented Code -- default code
//static void Main()
// ServiceBase[] ServicesToRun;
// ServicesToRun = new ServiceBase[]
// {
// new Service11()
// };
// ServiceBase.Run(ServicesToRun);

    1. For Deployment purpose we can make use of the installer package as mentioned in these articles MSDN, Torben M. Philippsen
Categories: .NET, General Tags:

Add properties to visual webparts sharepoint 2010

November 7, 2013 Leave a comment

This post talks on how one can add custom properties to their SharePoint 2010 visual webparts. Microsoft has brought visual webparts for easing the developer life with SharePoint 2010 development. But when it comes to adding some custom properties for these webparts then there is bit of trouble hidden.
To troubleshoot this issue lets us dive in entities inside webpart project.

  • Inside the webparts folder of the project one can see following files (considering webpart name as “VisualWebPart1”):
  1. Webpart class “VisualWebPart1.cs” that is derived from webpart class
  2. User control file “VisualWebPart1UserControl.ascx” and its associated designer and .cs files

Since we think that merely writing the property and setting its attributes to WebBrowsable=true & Personalizable inside the usercontrol class (VisualWebPart1UserControl.ascx.cs) file will go ahead and add properties into webpart, but in reality this will not work.
So how we gonna do this?
Even though the above assumption of ours is true but its partially true. The fact is, before adding this property to user control class we should

Invoke SSRS reports from ASP.NET and or sharepoint webpart application by passing parameters

October 22, 2013 Leave a comment

Hi All,

After a good long break getting back to what like to 🙂
In this post I’m planning to take you through the execution of SSRS reports from an ASP.NET application, now what is so great about this (simple its my first post after long break 🙂 ) because we will see how to pass parameters to the report. And these reports are bit special/unique because they are driven by an SSAS cube.
Ok so not to waste more time…
Here is the code for doing so:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;

namespace MyWebApp
public partial class DummyReportViewer : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
_reportViewer.ProcessingMode = ProcessingMode.Remote;
// Report Server URL
_reportViewer.ServerReport.ReportServerUrl = new Uri(“http://%5Bservername:portnumber%5D/ReportServer/&#8221;);
// Report Name
_reportViewer.ServerReport.ReportPath = “/[reportpath]/[rdl_file_name]”;
// set true to show report parameters else false
_reportViewer.ShowParameterPrompts = true;
_reportViewer.ShowPrintButton = true;
// Below code demonstrate the Parameter passing method. User only if you have parameters into the reports.
Microsoft.Reporting.WebForms.ReportParameter[] reportParameterCollection = new Microsoft.Reporting.WebForms.ReportParameter[4];
reportParameterCollection[0] = new ReportParameter(“prmUniversityZone”, @”[DIM Zone].[Zone Hierarchy].[Zone NM].&[All]”);
reportParameterCollection[1] = new ReportParameter(“prmEducationStream”, @”[DIM Education].[Education Hierarchy].[Stream DSC].&[Engineering]”);
reportParameterCollection[2] = new ReportParameter(“prmPeriod”, @”[DIM Time PERIOD].[Period Hierarchy].[Year DSC].&[2009]”);
reportParameterCollection[3] = new ReportParameter(“prmResult”, @”[DIM Result].[Result Hierarchy].[Result NM].&[All]”);


Ok so what in case of multiple values for a single parameter. So in that case instead of sending string of parameter value pass an string array of multiple values.

//instead of single parameter as:
reportParameterCollection[2] = new ReportParameter("prmPeriod", @"[DIM Time PERIOD].[Period Hierarchy].[Year DSC].&[2009]");

//create an string array of Year and pass it:
string[] years = new string[] { “2008”, “2009”, “2010”, “2011”, “2012” };
reportParameterCollection[2] = new ReportParameter(“prmPeriod”, years);

You may ask how do I extract this information of parameters. The simple is open the report goto parameters, open its property and check for Default Values in it. You will know what is required to be passed to the report parameter.

One more thing this is applicable to ASP.NET as well as SharePoint web part application

Following could be helpful resource for reports related stuff:


Categories: General Tags: , , ,

Dynamic and Editable GridView for SharePoint 2010

October 30, 2012 Leave a comment

Hi All,
This post of mine is kind of continuation my effort in developing of generalized utilities (specifically on grid layouts ).
Well here this time I had moved bit ahead and tried to develop an editable dynamic data grid which would be quite closure to what we get in datasheet view of SharePoint list. SharePoint 2010 is the targeted platform for this one.
For now I’m going to upload images of my latest buddy 🙂 Do have a look at it.
webparts custom properties in modal-dailogue

Sending HTML formated email from sql server

August 16, 2012 3 comments

Hi Folks,
After long time jolting something worth having glance. In application development we often come across a typical requirement where we are required to build a utility they will perform certain task(s) on periodic basis. One such type of common requirement is to shot mail(s) on periodic basis.
Recently I built one such utility for auto mailer. There were three (3) possible options to achieve this viz:

  1. Schedule an .exe application which will send emails
  2. Write an window service
  3. Create sql job and execute a sproc which will send email

Of these three options, last option has upper hand, as the data that required to be mailed was in database, also the sender email address and receiver email address were available in db and lastly there is no extra installer required since the job is defined in sql server and hence no deployment hiccups.

But the challenge was to build a dynamic HTML formatted email (challenge: because I underestimated send mail sproc of sqlserver).

But then bit of googling cleared my misconception and then I kick started building the auto mailer.

  • The rough layout of the desired html is as below:

Spot Nomination for July 2012

Emp.ID Employee Name Approver Payroll Amount Currency Mode
1 Joe Gracia Mark twain USA 1000 USD Cash
2 Narayan Jadhav Sam Powel USA 1000 USD Cash
3 Manish Patil Jignesh Patel India 4000 INR Cash
4 Amy Wang Lu Sang Taiwan 2000 TD Cash
5 Tsai Wu Sam Mochi Taiwan 2000 TD Cash
6 Juan Marcos Anna Alvaris Spain 1000 EURO Cash
7 Adongo Wangai Tobe Mugambe Kenya 4000 KES Cash
8 Akae Takahashi Chi Itou Japan 2000 YEN Cash
9 Mohit Gupta Ashutosh Singh India 4000 INR Cash

Thanks & Regards,
Payroll Management Team

  • The Logic for the Stored Procedure
  1. Create a temp table and define necessary columns in it
  2. Populate the temp table by inserting the required data into it
  3. Declare two variables viz @xml NVARCHAR(MAX); @body NVARCHAR(MAX);
  4. Extract the data from temp table, cast it to xml string (essentially with html tags in it) and then assign it to @xml variable
  5. Now this @xml variable is having partial, table formatted data of the body tag
  6. Now build the remaining part of the body tag
  7. At concluding part just execute the msdb.dbo.sp_mail_dbmail stored procedure and provide the @body variable to it
  • The complete sql script is as below:
CREATE PROCEDURE [dbo].[SendEmail_Date_AwardType_Location]
 @FromDate DateTime
 , @ToDate DateTime
 , @AwardTypeID Int
 , @LocationName Varchar(50)


CREATE TABLE #SpotNomApporval
 [EmpID] INT
 ,[EmployeeName] NVARCHAR(150)
 ,[Payroll] NVARCHAR(150)
 ,[ApprovingAuthority] NVARCHAR(150)
 ,[Amount] INT
 ,[Currency] NVARCHAR(150)
 ,[Mode] NVARCHAR(150)

INSERT INTO #SpotNomApporval
 ,[EmpName] AS [EmployeeName]
 , AI.[GlobalLocation] AS [Payroll]

FROM [AwardInfo] AS AI
 LEFT JOIN [AwardType] AS AT
 ON AI.AwardTypeID = AT.AwardTypeId
 LEFT JOIN [AwardLocation] AS AL
 ON AI.GlobalLocation = AL.LocationName
WHERE AT.AwardTypeId = @AwardTypeID
 AND AL.LocationName = @LocationName
 AND DateofRequisition BETWEEN @FromDate AND @ToDate

DECLARE @duration NVARCHAR(100);

SET @xml = CAST(( SELECT [EmpId] AS 'td'
 ,'',[EmployeeName] AS 'td'
 ,'',[ApprovingAuthority] AS 'td'
 ,'',[Payroll] AS 'td'
 ,'',[Amount] AS 'td'
 ,'',[Currency] AS 'td'
 ,'',[Mode] AS 'td'
FROM #SpotNomApporval

SET @duration = (SELECT Month =
 WHEN 1 THEN 'January'
 WHEN 2 THEN 'February'
 WHEN 3 THEN 'March'
 WHEN 4 THEN 'April'
 WHEN 5 THEN 'May'
 WHEN 6 THEN 'June'
 WHEN 7 THEN 'July'
 WHEN 8 THEN 'August'
 WHEN 9 THEN 'September'
 WHEN 10 THEN 'Octomber'
 WHEN 11 THEN 'November'
 WHEN 12 THEN 'December'

SET @body ='<html><body><span style="color:#17365d"><H3>Spot Nomination for '+@duration+'</H3></span>
<table border = 1>
<td bgcolor="#6B696B"> Emp.ID </td> <td bgcolor="#6B696B"> Employee Name </td> <td bgcolor="#6B696B"> Approver </td>
<td bgcolor="#6B696B"> Payroll </td> <td bgcolor="#6B696B"> Amount </td> <td bgcolor="#6B696B"> Currency </td>
<td bgcolor="#6B696B"> Mode </td></tr>'

SET @body = @body + @xml +'</table></body></html>'
SET @duration = 'Spot Nomination for '+@duration

EXEC msdb.dbo.sp_send_dbmail
@body = @body,
@body_format ='HTML',
@recipients = 'manishrao18@gmail.com',
@subject = @duration

DROP TABLE #SpotNomApporval


The more helpful resource can be found at below links:


Categories: Sql Server Tags:

Packt’s Microsoft Carnival!

May 15, 2012 Leave a comment

Brighten your May at Packt’s Microsoft Carnival! Exciting discounts on Microsoft books/e-books throughout May 2012!


Categories: General Tags:

Sharepoint 2010 powershell references

February 2, 2012 Leave a comment
Categories: General Tags:

Log files and TextWriterTraceListener

February 1, 2012 2 comments

Writing a log file using TraceListner classes its just one more way of writing logs..  🙂

private int Logger(Exception exObj)
using (Stream myFile = File.Exists(“TestFile.txt”) ? File.Open(“TestFile.txt”, FileMode.Append) : File.Create(“TestFile.txt”))
/* Create a new text writer using the output stream, and add it to * the trace listeners. */
TextWriterTraceListener myTextListener = new TextWriterTraceListener(myFile);
// Write output to the file.
Trace.Write(“\r\n Test output \r\n”);
Trace.Write(“\r\n Test output \r\n”);

// Flush the output.

Trace.Listeners.Remove(myTextListener); // this is very important else you may encounter error wrt file/stream/trace object
return 0;

Categories: General Tags: , ,