1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

file-base dotnet run が出たはいいものの

Posted at

file-base dotnet run が net10.0 (preview) でリリースされました。

これにより 手軽に ライブラリの実行例が作成できるようになりましたが……。

ファイル置き場はどこが適切か問題

皆さんは 実行用 cs ファイルは どこに置いていますでしょうか?

私は下記の様な構造にしています。


root
├ solution.slnx
├ Directory.Build.props
├ Directory.Build.targets
├ Library1
│ ├ Library1.csproj
│ └ ...
├ Libarry2
│ ├ Library2.csproj
│ └ ...
└ scripts
  ├ appsettings.json
  ├ appsettings.Development.json
  ├ Program1.cs
  ├ Program2.cs
  └ ...

これの利点は スクリプトの階層が Directory.Build.props / Directory.Build.targets が利く場所なので
また、 appsettings.json / appssettings.Development.json の利く場所なのでやりやすい というのがあります。

具体的には次の様なコードが書けます。

#!/usr/local/share/dotnet/dotnet run
#:package Microsoft.Extensions.Hosting
#:project ../Library1
#:property PublishAot=false
#:property UserSecretsId=project-web        
#:property RootNamespace=Program1

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
// ...
var host = Host.CreateApplicationBuilder(args);
// ....

実行するときは先述の様に

scripts ディレクトリに移動して 次の様な実行となります。

dotnet run Program1.cs -- --environment Development

ただ、これは VisualStudio の 基本機能では実行手段がターミナルしかないのでつらいです。

まとめ

皆さんは file-base dotnet run をどう使っていますでしょうか?

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?