Memw
Memw
CC#
Created by Memw on 5/27/2024 in #help
Targets not running
So I was testing with msbuild properties and I have a target that's supposed to show a message, but the target doesn't even run, I feel I'm missing something
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<Reference Include="MemwLib">
<HintPath>..\MemwLib\bin\AnyCPU_Debug\MemwLib\net7.0\MemwLib.dll</HintPath>
</Reference>
</ItemGroup>

<Target Name="lmfao" AfterTargets="AfterBuild">
<ItemGroup>
<Message Text="Hello $(TargetDir)" Importance="High"/>
</ItemGroup>
</Target>
</Project>
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<Reference Include="MemwLib">
<HintPath>..\MemwLib\bin\AnyCPU_Debug\MemwLib\net7.0\MemwLib.dll</HintPath>
</Reference>
</ItemGroup>

<Target Name="lmfao" AfterTargets="AfterBuild">
<ItemGroup>
<Message Text="Hello $(TargetDir)" Importance="High"/>
</ItemGroup>
</Target>
</Project>
The target that should run is the "lmfao" one
1 replies
CC#
Created by Memw on 5/25/2024 in #help
Running custom build targets within library user
I have all my code to implement views within a big HTTP library I'm making, that parses files with html and c# together with custom expressions and all. I was thinking that the best way would be leaving the user of the library (the library can be installed trough nuget) to declare a property like Views or something like that with a path, and then my library would copy these files from the user specified path to the user project bin so the library has access to those, any other suggestions on how to open view files for the library to access. For now I was thinking on the first part, it would be possible to make a custom property available to the users csproj and running a target like
<Target Name="CopyMemwLibViews" BeforeTargets="Build">
<Copy Condition="Exists('$(Views)')" SourceFiles="$(Views)" DestinationFolder="$(OutputPath)\Views" />
</Target>
<Target Name="CopyMemwLibViews" BeforeTargets="Build">
<Copy Condition="Exists('$(Views)')" SourceFiles="$(Views)" DestinationFolder="$(OutputPath)\Views" />
</Target>
if the user has that property declared in their csproj?
9 replies
CC#
Created by Memw on 2/14/2024 in #help
HostedService stopping infinitely
I'm making a discord bot that has some other services running and I don't seem to get why when I try to stop my application it just be Application is being stopped I'd assume some process is blocking but I don't see any way of debugging that, I checked everywhere but I don't see anything the potential problem might be that Program.cs
private static async Task Main()
{
StartApplication();

CancellationTokenSource ctSource;

do
{
ctSource = Services.GetRequiredService<CancellationTokenSource>();
await Task.Delay(TimeSpan.FromSeconds(1), ctSource.Token);
} while (!ctSource.IsCancellationRequested);
}

public static void StartApplication()
=> Provider.Start();

private static IHost CreateProvider()
{
DiscordSocketClient client = new(new DiscordSocketConfig
{
AlwaysDownloadUsers = true,
AuditLogCacheSize = 1000,
GatewayIntents = GatewayIntents.All
});

// TODO: change to type.
EnvContext settings = new EnvContext()
.AddVariablesFrom(File.Open(".env", FileMode.Open), true);

HostApplicationBuilder builder = new HostApplicationBuilder();

builder.Services
.AddSingleton(client)
.AddSingleton(settings)
.AddSingleton(x => new InteractionService(x.GetRequiredService<DiscordSocketClient>()))
.AddSingleton<CancellationTokenSource>()
.AddHostedService<ExceptionCatcherService>()
.AddHostedService<BotStartService>()
.BuildServiceProvider();

return builder.Build();
}
private static async Task Main()
{
StartApplication();

CancellationTokenSource ctSource;

do
{
ctSource = Services.GetRequiredService<CancellationTokenSource>();
await Task.Delay(TimeSpan.FromSeconds(1), ctSource.Token);
} while (!ctSource.IsCancellationRequested);
}

public static void StartApplication()
=> Provider.Start();

private static IHost CreateProvider()
{
DiscordSocketClient client = new(new DiscordSocketConfig
{
AlwaysDownloadUsers = true,
AuditLogCacheSize = 1000,
GatewayIntents = GatewayIntents.All
});

// TODO: change to type.
EnvContext settings = new EnvContext()
.AddVariablesFrom(File.Open(".env", FileMode.Open), true);

HostApplicationBuilder builder = new HostApplicationBuilder();

builder.Services
.AddSingleton(client)
.AddSingleton(settings)
.AddSingleton(x => new InteractionService(x.GetRequiredService<DiscordSocketClient>()))
.AddSingleton<CancellationTokenSource>()
.AddHostedService<ExceptionCatcherService>()
.AddHostedService<BotStartService>()
.BuildServiceProvider();

return builder.Build();
}
and I have a service running that's ExceptionCatcherService which should log any unhandled exception and restart the HostedService
public override async Task StopAsync(CancellationToken cancellationToken)
{
await base.StopAsync(cancellationToken);
await ct.CancelAsync();
}
public override async Task StopAsync(CancellationToken cancellationToken)
{
await base.StopAsync(cancellationToken);
await ct.CancelAsync();
}
3 replies