-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NativeAOT publish for DLL does not set automatically RID #29834
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsI was have following setup. DLL project which I publish as NativeAOT. I have to publish it
|
In .NET 7+, dotnet-publish sets the RID implicitly to the runtime of executing dotnet.exe with You can also pass
|
I know about that, but if you create dotnet new winforms
# remove OutputType
dotnet publish then you will have situation like I describe. Probably MVC is special cased somehow. |
Well, I tested with two templates: Console and MVC. WinForms is rather an exception.
I don't see PublishAot specified anywhere. |
You may take a look at this project https://github.com/kant2002/WinFormsComInterop/blob/main/samples/HostedWindowsForms/HostedWindowsForms.csproj which was led to following error kant2002/WinFormsComInterop#48 (comment) if using |
I think issue is specifically for |
Yes, classlib requires the runtime argument: $ dotnet new classlib -n lib1
$ dotnet publish lib1 -p:PublishAot=true --use-current-runtime |
I see two problems here, why |
Your sample https://github.com/kant2002/WinFormsComInterop/tree/main/samples/HostedWindowsForms is building on my Win10 box with .NET SDK 7.0.101 without dotnet publish --use-current-runtime
::: or
dotnet publish -r win-x64
...
Generating native code
... produces |
I belive you are did not notice |
Sounds like this should be an error. |
ILC reporting is separate issue. I'm worry only about SDK behavior. It seems reasonable that if |
This is probably because publishing a library mostly works by accident in the SDK and wasn't fully tested for everything. dotnet/linker#3165 (comment). Looks like it doesn't even work for all NativeAOT scenarios (although WinForms with NativeAOT is definitely not a supported scenario in 7.0).
Nope, people add assemblies their grandmother wrote for .NET Framework 1.0 to their .NET 7 apps and expect the parts that work with a JIT-based runtime to also work on an AOT-based runtime. (I.e. publishing apps with missing or mismatched dependencies is common so the compiler makes a reasonable attempt to emulate the JIT behavior where one would get an exception only once a problematic codepath is reached.) |
So we have one more case in addition to Android where publish self-contained libraries make sense. Is this should be better documented in sample, or SDK work? |
It already mostly works for NativeAOT. Did you hit it in a scenario that doesn't involve WinForms? We don't document/make samples for things that are unsupported. (I assume the problem is that WinForms adds itself to publish differently than regular NuGet packages and we need a fix in the .NET SDK or WinForms SDK to do it in a way that works with NativeAOT. Basically the SDKs don't expect publishing as libraries and may need extra work.) |
Does failure of embed of ASP.NET Core count as "supported" scenario? I test it and it produce |
ASP.NET Core is also not supported with NativeAOT. It's only a .NET 7 servicing-worthy issue if this doesn't work with regular NuGets. Otherwise this would be "help-wanted", milestoned as "Future". |
I think it affects only cases where library distinguish between self-contained and not self-contained modes. I do not aware of non-MS and popular enough Sdks which do this. So be it -"help wanted" and "Future". Any chance that sdk repo(am I right?) would accept contributions in this area? Once ASP.NET Core make significant progress in NativeAOT I think this issue will re-appear, since I bet some people try to put it in the unmanaged app. |
If most (or all) of the |
NativeAOT has the unwanted privilege of being basically the first scenario in which library project needs to be published self-contained. (publishing library project itself is somewhat undefined operation in SDK, making it self-contained is just making it worse). Android apps are like this already, but I think they go well outside the normal SDK integration, so it's not a fair comparison.
I don't see why it wouldn't. I think the toughest part is actually defining what it means to do these things. And then reconciling that with existing behavior which is most likely different and thus it will be a breaking change. |
This is definitely an SDK issue, but I don't agree with the idea of turning the automatic RID on for everything... in fact it was like that during part of 7.0.100, and it broke a lot of people. But @kant2002 is 💯 % right in that it's the fact that it's a library that's the reason there is no implicit RID. The RID only is inferred for executable projects, there are a lot of library projects: EX for a classlib, Maybe the suggestion is for |
Were those people using |
The issues were not with publish itself, they were that setting |
I see, so
Could you explain why it wouldn't make sense? In my understanding, NativeAOT publishing requires RID (mandatory). We are inferring RID for !IsRidAgnostic cases in .NET 7. So I don't see a reason why we should let |
That was an issue but not the one I was referring to. There was a different one where VS was broken because of library projects getting a RID, and builds working that shouldn't have worked. #28628
The specific issue was with |
Sorry, typo. I meant to say that it does make sense to default a RID when publishing a library as NativeAOT. Lot of the complexity comes from the fact that we want to default the RID typically only when publishing. Building a library because it's a dependency of some other project should not be affected by publish properties. But unfortunately the way SDK/msbuild currently operates the RID defaulting has to happen early on. I'm definitely no expert in that area though - I'll leave it to @nagilson to comment on the feasibility of doing this. Things which I find "interesting":
|
I would like to split discussion in two parts. Seems to be for Regarding RID. My understanding that |
ATM, we can limit the inference only by the
Currently it wouldn't get the inference. As above, we could change the behavior for build and publish on the app. But we'd need a MSBuild property that is available early on to tell the difference between a Library that's
Currently it shouldn't do anything.
This I'm unsure of.
Before 7.0.200 it did for every property that gets inference, in 7.0.200 only
Would need to look into |
I am having the same issue, this error just shows when the project is set the PublishAot = true and FrameworkDependent if I try to set my project as SelfContained I have ILC Compile errors
|
@dougkl :
What do you want to achieve by this setup? Currently NativeAOT doesn't support anything but self-contained mode (it will always include the runtime in the final binary). For the compiler crash (when self-contained is enabled), could you please create a new issue in the dotnet/runtime repo? |
@vitek-karas just did dotnet/runtime#105947 thanks |
I was have following setup. DLL project which I publish as NativeAOT. I have to publish it
dotnet publish -r win-x64 --self-contained
otherwise project does not pickup nor current RID of my dev machine, not the fact that application is self-contained (NativeAOT). It's most likely issue in SDKdotnet publish
want me specify RIDdotnet publish -r win-x64
use WinForms references during build, but do not propagate them for publish to ILCdotnet publish -r win-x64 --self-contained
works, butself-contained
switch is misleading probably and undo a lot of tooling work in recent releases around NativeAOTThe text was updated successfully, but these errors were encountered: