C
C#•6mo ago
Esa

dotnet publish fails due to a build error that doesn't happen when I run just dotnet build

Hi there, I'm having a weird thing going on here. I use Jetbrains Rider, and have a project that uses a class library a colleague made. The error that is happening says that Required member X.Y must be set in the object initializer or attribute constructor. And this is super weird to see as an Error and not a warning, because 1) we never instantiate that class, it's resolved through DI and 2) this works in a regular build. So it's only during the publish part this goes wrong. I don't even know where to begin troubleshooting this. Any advice?
15 Replies
Pobiega
Pobiega•6mo ago
Do you get the same behaviour when doing build/publish via Cli instead of via rider?
Angius
Angius•6mo ago
Is it maybe an AoT publish? Regular run might be setting that required prop via relfections, while AoT might be trying to not use reflection there
Pobiega
Pobiega•6mo ago
Yeah thats my guess too
Esa
EsaOP•6mo ago
I haven't actually tried these things manually I'll give it a try
Pobiega
Pobiega•6mo ago
What publish arguments are you using?
Esa
EsaOP•6mo ago
so now I just tried a plain dotnet publish, and that worked
Pobiega
Pobiega•6mo ago
You could just do a --nobuild or whatever the flag is, if its a "normal" publish
Esa
EsaOP•6mo ago
but the publish I've set up, is like this
No description
Pobiega
Pobiega•6mo ago
$singlefile
MODiX
MODiX•6mo ago
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true Use of -p:PublishSingleFile=true implies --self-contained true. Add --self-contained false to publish as runtime-dependent. -r RID and -p:PublishSingleFile=true can be moved to .csproj as the following properties:
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
but to target multiple RIDs, you have to use dotnet publish with the -r option for each RID. You can also add -p:IncludeNativeLibrariesForSelfExtract=true to include native libraries (like Common Language Runtime dlls) in the output executable. You might want to instead publish your application compiled Ahead Of Time to native code, see $nativeaot for examples. Single file publishing | Runtime Identifier (RID) catalog | dotnet publish
Pobiega
Pobiega•6mo ago
Use the above to reproduce that publish from CLI, see if you get the same error
Esa
EsaOP•6mo ago
Hm, what's a runtime identifier in this case?
Pobiega
Pobiega•6mo ago
Win-x64
Esa
EsaOP•6mo ago
dotnet publish -c Release -r win-x64 -p:PublishSingleFile=true This command also worked 🤔
Pobiega
Pobiega•6mo ago
only difference I can see then is the trimming
Want results from more Discord servers?
Add your server