Micro blog about Answer to the Ultimate Question of Life, the Universe, and Everything.
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
      • Côte d'Azur 2024
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home
  3. C#

Change output path without adding target framework

Details
Written by: Stanko Milosev
Category: C#
Published: 28 February 2021
Last Updated: 07 November 2021
Hits: 3556
  • core
  • visual studio
If in Visual Studio I just change "Output path", VS will always add target framework to folder structure, like "netcoreapp3.1" ("C:\projects\EFCore\tools\netcoreapp3.1"), in order to avoid this, right click on the project, click on "Edit Project File" and add:
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
From here

Entity framework Core MySql scaffolding example

Details
Written by: Stanko Milosev
Category: C#
Published: 27 February 2021
Last Updated: 07 November 2021
Hits: 3581
  • core
Mostly I was using this web site for my example.

In my case I have created the project C:\projects\ReverseGeoCoding, then open PowerShell, and first, if you don't have EF tool installed, execute following:

dotnet tool install --global dotnet-ef
Go to project folder, like cd "C:\projects\ReverseGeoCoding", and add packages "Microsoft.EntityFrameworkCore.Design" and "MySql.EntityFrameworkCore" like:
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package MySql.EntityFrameworkCore --version 5.0.0-m8.0.23
Now scaffold:
dotnet ef dbcontext scaffold "SERVER=localhost;DATABASE=myDb;UID=uid;PASSWORD=pass;" MySql.EntityFrameworkCore -o C:\projects\ReverseGeoCoding -f
Now, I have made my own console applicatcation for scaffolding:
using System.Diagnostics;
using System.Threading;

namespace MySQLScaffold
{
  class Program
  {
    static void Main(string[] args)
    {
      // Use ProcessStartInfo class
      ProcessStartInfo startInfo = new ProcessStartInfo
      {
        CreateNoWindow = false,
        UseShellExecute = false,
        FileName = "dotnet",
        WindowStyle = ProcessWindowStyle.Hidden,
        Arguments = "ef dbcontext scaffold"
                    + " \"SERVER=localhost;DATABASE=myDb;UID=uid;PASSWORD=pass;\""
                    + " MySql.EntityFrameworkCore -o"
                    + " C:\\projects\\ReverseGeoCoding"
                    + " -f -v"
                    + " -p C:\\projects\\ReverseGeoCoding"
      };

      Mutex myMutex;
      if (!Mutex.TryOpenExisting("testMutex", out myMutex))
      {
        myMutex = new Mutex(true, "testMutex");
        myMutex.WaitOne();
        try
        {
          // Start the process with the info we specified.
          // Call WaitForExit and then the using statement will close.
          using (Process exeProcess = Process.Start(startInfo))
          {
            exeProcess?.WaitForExit();
          }
        }
        catch
        {
          // Log error.
        }
        finally
        {
          myMutex.ReleaseMutex();
        }
      }

      //Console.WriteLine("Press any key");
      //Console.ReadKey();
    }
  }
}
Then I have created Class library application "EFCore", where in prebuild event I have added
C:\projects\MySQLScaffold\MySQLScaffold\bin\Debug\netcoreapp3.1\MySQLScaffold.exe
I had to add package "Microsoft.EntityFrameworkCore.Design", and I had to reference my "ReverseGeoCoding" project, here is how my "EFCore.csproj" look like:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="C:\projects\MySQLScaffold\MySQLScaffold\bin\Debug\netcoreapp3.1\MySQLScaffold.exe" />
  </Target>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\ReverseGeoCoding\ReverseGeoCoding.csproj" />
  </ItemGroup>

</Project>

Pre-build events

Details
Written by: Stanko Milosev
Category: C#
Published: 12 February 2021
Last Updated: 12 February 2021
Hits: 3024
  • visual studio
In order to save output of your Pre-build Events write something like:

echo ProjectDir=$(ProjectDir) >>$(TEMP)\macros.txt
Then open file %temp%\macros.txt

List of Macros you can see in Edit Pre-Build -> Macros >>

Split string in four blocks

Details
Written by: Stanko Milosev
Category: C#
Published: 05 October 2020
Last Updated: 05 October 2020
Hits: 3459
  • regular expressions
One example on how to display IBAN in four blocks:
Regex.Replace("DE89370400440532013000", ".{4}", "$0 ");
  1. LINQ to XML duplicated Node
  2. Detect the encoding/codepage of a text file
  3. Read file in chunks
  4. List.Contains

Subcategories

WPF

Beginning

Code snippets

NUnit

LINQ

Windows Forms

Page 11 of 38

  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15