Skip to content

Instantly share code, notes, and snippets.

@seclerp
Created November 15, 2022 16:53
Show Gist options
  • Save seclerp/352f6b79817dfb8d3c3afb64dbfbb49b to your computer and use it in GitHub Desktop.
Save seclerp/352f6b79817dfb8d3c3afb64dbfbb49b to your computer and use it in GitHub Desktop.
Solution for the task "Run the Java Hello World example via both dotnet run and javac"
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<Target Name="GenerateCsharp" BeforeTargets="BeforeBuild" KeepDuplicateOutputs="true">
<WriteLinesToFile File="Program.generated.cs" Overwrite="true" Encoding="Unicode" Lines="$([System.IO.File]::ReadAllText('Program.java').Replace('main','Main').Replace('System.out.println','System.Console.WriteLine'))" />
<ItemGroup>
<Compile Include="Program.generated.cs" />
</ItemGroup>
</Target>
</Project>
class Program {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
@kant2002
Copy link

Забув .Replace('String','string')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment