Friday, September 26, 2025

Setup .NET modules support multiple framework

Environment requirement

  • Visual Studio 2019/2022 (with .NET SDK)
  • dotnet CLI (dotnet --version)
  • Access to your private feed, e.g. nuget.local
  • Your API key (e.g. nugetfeed)

Enable multi-framework (multi-targeting) at project configuration file(.csproj)

Visual Studio’s GUI only lets you pick one framework. To target multiple, edit the project file.
  1. In Solution Explorer → right-click the project → Edit Project File.
  2. Replace <TargetFramework> with <TargetFrameworks> (semicolon-separated).
For exmple

 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
  

Fill nuget package metadata in Visual Studio

  1. Right-click project → Properties → Package tab.
  2. Fill:
    • Package ID: Geo.OpenDataExtender
    • Version: e.g., 1.0.0
    • Authors, Company, Description, Repository URL, License (if applicable)
For exmple



After filled

1. Open windows console at the main project file. Then input commend to package module.
dotnet pack -c Release
The result will like this


2. Push the module to nuget server.
ddotnet nuget push bin\Release\module.version.nupkg --source "https://nuget.geo.local/nuget" --api-key geo.developer --skip-duplicate
For exmple
dotnet nuget push bin\Release\Geo.OpenDataExtender.1.0.0.nupkg --source "https://nuget.local" --api-key nugetfeed --skip-duplicate

Finally

Choose any project and manage nuget packages. Check whether the module has been uploaded successfully.

Sunday, January 21, 2024

MS SQL deal with Date or Datetime

In C#, to create DateTime is easy. It could be the following.

DateTime datetime = new DateTime(2024, 1, 1);

After SQL Server 2016 (13.x), there is a new a function has been introduced which is DATEFROMPARTS.
We can declare the Date or DateTime more intuitively.

Date

SELECT DATEFROMPARTS( 2024, 1, 1) AS  Result;

DateTime

SELECT DATETIMEFROMPARTS( 2024, 1, 1, 0, 0, 0, 0) AS  Result;

It becomes more graceful.

Friday, December 14, 2018

[強制險]強制險申請

給有需要申請的人參考

到保險公司申請強制險理賠時,須具備

登記聯單(影印的要去警局蓋章)
身分證影本
駕照影本
行照影本
現場圖
初判表(可有可無?)
診斷證明書(正本or 副本要蓋章)
醫療收據(正本 or 副本要蓋章)
保險公司的申請書
印章
存摺封面影本


可以申請交通費 (不需要收據,要詢問怎麼申請)

Thursday, June 28, 2018

[Google Driver API]Uploading and viewing file by Google Driver API

There is a solution for uploading and viewing file by Gooole Driver API.

Step 1 Enable Google API nad get the client_secret

 Here is the official reference link: https://developers.google.com/drive/api/v3/quickstart/js

a. Create your project
b. On the Add credentials to your project page, click the Cancel button

c. At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button

d. Select the Credentials tab, click the Create credentials button and select OAuth client ID.
e. Dowload the client_secret.json


f. Put the client_secret.json to your project.


Step 2 Install Google.Apis.Driver.v3 as Nuget


Step 3 Write code in your Controller

static string[] Scopes = { DriveService.Scope.Drive };
static string ApplicationName = "Drive API .NET Quickstart";

private DriveService GetService()
{
     UserCredential credential;

     using (var stream = new FileStream(Server.MapPath("~/Content/client_secret.json"), FileMode.Open, FileAccess.Read))
     {
          string credPath = System.Environment.GetFolderPath(
          System.Environment.SpecialFolder.Personal);

          credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");

          credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
     }

     // Create Drive API service.
     var service = new DriveService(new BaseClientService.Initializer()
     {
          HttpClientInitializer = credential,
          ApplicationName = ApplicationName,
     });

     return service;
}
public ActionResult Upload()
{
     DriveService service = GetService();

     string fileName = "template.odt";

     var fileMetadata = new Google.Apis.Drive.v3.Data.File()
     {
          Name = fileName,
          MimeType = MimeMapping.GetMimeMapping(fileName)
     };

      FilesResource.CreateMediaUpload request;
      using (var stream = new System.IO.FileStream(Server.MapPath("~/Content/template.odt"), System.IO.FileMode.Open))//~/Content/template.odt is your file location
      {
           request = service.Files.Create(
                    fileMetadata,
                    stream,
                    MimeMapping.GetMimeMapping(fileName));
                    request.Fields = "id";
                    request.Upload();
      }
      var ftwile = request.ResponseBody;

      return Redirect(string.Format("https://drive.google.com/file/d/{0}/view", ftwile.Id));
}
Just put
<a href='@Url.Action("Upload")'>Upload</a>
on your View file.
Click the link it will upload file and open the file on google driver.

Friday, May 29, 2015