astral
astral
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
This is csproj of one level up:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<!-- Add NoteBoxGenerator -->
<ItemGroup>
<ProjectReference Include=".\NoteBoxGenerator\NoteBoxGenerator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<!-- Add NoteBoxGenerator -->
<ItemGroup>
<ProjectReference Include=".\NoteBoxGenerator\NoteBoxGenerator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
</ItemGroup>

</Project>
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
I can't seem to get it to build - smthn with the csproj:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
</ItemGroup>

</Project>
/home/amber/dox/dev/note-box.git/main/NoteBoxGenerator/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [/home/amber/dox/dev/note-box.git/main/note-box.csproj]
/home/amber/dox/dev/note-box.git/main/NoteBoxGenerator/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [/home/amber/dox/dev/note-box.git/main/note-box.csproj]
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
I have this generator:
using Microsoft.CodeAnalysis;

namespace SourceGenerator;

[Generator]
public class NoteBoxGenerator : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
// Code generation

// List of utilities
string[] utils = {
"true",
"false",
"echo",
};

// Construct switch block
string switchBlock = string.Empty;
foreach (var util in utils)
{
switchBlock += $@"
case ""{util}"": ret = {util.First().ToString().ToUpper() + util[1..]}.{util.First().ToString().ToUpper() + util[1..] + "Main"}; break;
";
}

string source = $@"
using System;

namespace NoteBox;

class NoteBox
{{
static void Main(string[] args)
{{
int ret = 0;

// switch block - e.g.
switch (args[0])
{{
{switchBlock}
}}

Console.WriteLine(""Hello, NoteBox!"");

Environment.Exit(ret);
}}
}}
";

context.AddSource("NoteBox.g.cs", source);
}

public void Initialize(GeneratorInitializationContext context)
{
// Initialization
}
}
using Microsoft.CodeAnalysis;

namespace SourceGenerator;

[Generator]
public class NoteBoxGenerator : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
// Code generation

// List of utilities
string[] utils = {
"true",
"false",
"echo",
};

// Construct switch block
string switchBlock = string.Empty;
foreach (var util in utils)
{
switchBlock += $@"
case ""{util}"": ret = {util.First().ToString().ToUpper() + util[1..]}.{util.First().ToString().ToUpper() + util[1..] + "Main"}; break;
";
}

string source = $@"
using System;

namespace NoteBox;

class NoteBox
{{
static void Main(string[] args)
{{
int ret = 0;

// switch block - e.g.
switch (args[0])
{{
{switchBlock}
}}

Console.WriteLine(""Hello, NoteBox!"");

Environment.Exit(ret);
}}
}}
";

context.AddSource("NoteBox.g.cs", source);
}

public void Initialize(GeneratorInitializationContext context)
{
// Initialization
}
}
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
ill brb imma tinker with system.environment and see if theres something to read link names
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
This seems to work, too:
<Target Name="PostBuild" AfterTargets="PostBuild">
<PropertyGroup>
<BuildDir>$(OutputPath)/note-box/</BuildDir>
</PropertyGroup>

<!-- Ensure the builddir/note-box directory exists -->
<Exec Command="mkdir -p $(BuildDir)" />

<!-- Create symbolic links -->
<Exec Command="ln -sf note-box $(BuildDir)/true" />
<Exec Command="ln -sf note-box $(BuildDir)/false" />
<Exec Command="ln -sf note-box $(BuildDir)/echo" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuild">
<PropertyGroup>
<BuildDir>$(OutputPath)/note-box/</BuildDir>
</PropertyGroup>

<!-- Ensure the builddir/note-box directory exists -->
<Exec Command="mkdir -p $(BuildDir)" />

<!-- Create symbolic links -->
<Exec Command="ln -sf note-box $(BuildDir)/true" />
<Exec Command="ln -sf note-box $(BuildDir)/false" />
<Exec Command="ln -sf note-box $(BuildDir)/echo" />
</Target>
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
at the moment I just manually made the link:
cd bin
ln -sf note-box true
cd ..
dotnet build
./bin/true
cd bin
ln -sf note-box true
cd ..
dotnet build
./bin/true
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
I tried this:
string linkName = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
string linkName = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
which gives me note-box.dll
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
i tried making a symlink and errored its out of bounds
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
That only seemed to work when passing it as an arg
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
I found a solution 😃
string cmd = Environment.CommandLine.Split(' ')[1];
string cmd = Environment.CommandLine.Split(' ')[1];
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
I'll see if I can tinker around and get only the second part of it
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
hmm, GetCommandLineArgs() gives me argv. I found Environment.CommandLine, which gives /home/amber/dox/dev/note-box.git/main/bin/Debug/net8.0/note-box.dll true.
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
Okay, I'll try it out ^^
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
Maybe System.Environment has something to read link path. I'll check ^^
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
i want to try and write something like this https://github.com/astralchan/astral-box in c# / dotnet. something to tinker with ^^
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
because that is the design scope
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
Yes. The idea is to be able to call ./bin/echo instead of ./bin/note-box echo ^^
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
let's say I have this:
note-box.csproj
bin/
- note-box*
- echo@ -> note-box
- true@ -> note-box
- false@ -> note-box
note-box.csproj
bin/
- note-box*
- echo@ -> note-box
- true@ -> note-box
- false@ -> note-box
And the goal is calling ./bin/<util> shall invoke ./bin/note-box <util> to call that util.
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
From ISO/IEC 9899:1999
7.21.5.5 The strrchr function
Synopsis
1 #include <string.h>
char *strrchr(const char *s, int c);
Description
2 The strrchr function locates the last occurrence of c (converted to a char) in the
string pointed to by s. The terminating null character is considered to be part of the
string.
Returns
3 The strrchr function returns a pointer to the character, or a null pointer if c does not
occur in the string.
7.21.5.5 The strrchr function
Synopsis
1 #include <string.h>
char *strrchr(const char *s, int c);
Description
2 The strrchr function locates the last occurrence of c (converted to a char) in the
string pointed to by s. The terminating null character is considered to be part of the
string.
Returns
3 The strrchr function returns a pointer to the character, or a null pointer if c does not
occur in the string.
39 replies
CC#
Created by astral on 9/20/2024 in #help
How to Build Multiple Binaries from Dotnet New Console?
i looked into ISO / IEC 9899:1999 a little more and found strrchr returns points to last known path starting with what was specified in second arg
39 replies