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
Do you get the same behaviour when doing build/publish via Cli instead of via rider?
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
Yeah thats my guess too
I haven't actually tried these things manually
I'll give it a try
What publish arguments are you using?
so now I just tried a plain
dotnet publish
, and that workedYou could just do a --nobuild or whatever the flag is, if its a "normal" publish
but the publish I've set up, is like this
$singlefile
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: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
Use the above to reproduce that publish from CLI, see if you get the same error
Hm, what's a runtime identifier in this case?
Win-x64
dotnet publish -c Release -r win-x64 -p:PublishSingleFile=true
This command also worked
🤔only difference I can see then is the trimming