title: .net 6 console app : Pre-Compile not work well, neither Crossgen or Publish with ready to run or Publish to Signal App
body: <p>i want to pre-compile my .net 6 code to speed up first call of the method, something like <a href="https://docs.microsoft.com/en-us/dotnet/framework/tools/ngen-exe-native-image-generator" rel="nofollow noreferrer">ngen.exe</a> do during NetFamework age.</p>
  <p>I have a .net 6 testing console app, as simple as below:</p>
  <pre><code>internal class Program
  {
      private static readonly Stopwatch Stopwatch = new Stopwatch();
      private static int Delay = 3000;
      static void Main(string[] args)
      {
          var end = DateTime.Now.AddMilliseconds(Delay);
          while (DateTime.Now &lt; end)
          {
              continue;
          }
          Stopwatch.Start();
          Console.WriteLine(&quot;Test 1&quot;);
          Stopwatch.Stop();
          Console.WriteLine($&quot;Cost[{Stopwatch.ElapsedMilliseconds}]ms&quot;);
          Stopwatch.Restart();
          Console.WriteLine(&quot;Test 2&quot;);
          Stopwatch.Stop();
          Console.WriteLine($&quot;Cost[{Stopwatch.ElapsedMilliseconds}]ms&quot;);
          Console.ReadLine();
      }
  }
  </code></pre>
  <p>i try these methods, there are not work well when i run it.</p>
  <blockquote>
  <p><a href="https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/crossgen.md" rel="nofollow noreferrer">corssgen</a></p>
  </blockquote>
  <pre><code># Publish
  $ cd /home/root/src/Tester
  $ dotnet publish Tester.csproj -o bin/publish -f net6.0 -c Release -r linux-x64 -p:UseAppHost=true --self-contained=false
  
  # Crossgen2
  $ cd /home/root/bin/crossgen2.linux-x64.6.0.5
  $ ./crossgen2 -r . --targetarch x64 --targetos linux /home/root/src/Tester/bin/publish/Tester.dll --out /home/root/src/Tester/bin/crossgen/Tester.dll
  
  $ cp /home/root/src/Tester/bin/publish/Tester.deps.json /home/root/src/Tester/bin/crossgen
  $ dotnet /home/root/src/Tester/bin/crossgen/Tester.dll
  </code></pre>
  <blockquote>
  <p><a href="https://docs.microsoft.com/en-us/dotnet/core/deploying/ready-to-run" rel="nofollow noreferrer">deploying/ready-to-run</a></p>
  </blockquote>
  <pre><code>$ cd /home/root/src/Tester
  $ dotnet publish  -o bin/readyToRun -f net6.0 -c Release -r linux-x64 --self-contained=false -p:PublishReadyToRun=true
  $ dotnet /home/root/src/Tester/readyToRun/Tester.dll
  </code></pre>
  <blockquote>
  <p><a href="https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file/overview" rel="nofollow noreferrer">deploying/single-file</a></p>
  </blockquote>
  <pre><code>$ cd /home/root/src/Tester
  $ dotnet publish -o bin/native -f net6.0 -c Release -r linux-x64 -p:UseAppHost=true --self-contained=true -p:PublishSingleFile=true -p:PublishTrimmed=true
  $ dotnet /home/root/src/Tester/native/Tester.dll
  </code></pre>
  <blockquote>
  <p><a href="https://docs.microsoft.com/en-us/dotnet/core/deploying/native-aot" rel="nofollow noreferrer">native-aot</a></p>
  </blockquote>
  <pre><code>$ cp -rf /home/root/src/Tester /home/root/src/Tester_AOT
  $ vi /home/root/src/Tester_AOT/Tester.csproj
  &lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;
    &lt;PropertyGroup&gt;
      &lt;OutputType&gt;Exe&lt;/OutputType&gt;
      &lt;TargetFramework&gt;net6.0&lt;/TargetFramework&gt;
      &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;
      &lt;Nullable&gt;enable&lt;/Nullable&gt;
      &lt;PublishAot&gt;true&lt;/PublishAot&gt;
    &lt;/PropertyGroup&gt;
  &lt;/Project&gt;
  
  $ cd /home/root/src/Tester_AOT
  $ dotnet publish -r linux-x64 -c Release -p:UseAppHost=true --self-contained=false
  $ dotnet bin/Release/net6.0/linux-x64/publish/Tester.dll
  </code></pre>
  <p>there output similar like</p>
  <pre><code>Test 1
  Cost[9]ms
  Test 2
  Cost[0]ms
  </code></pre>
  <p>if any one can tell me the right way to do this , many thanks.</p>