-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Publishing standalone app (C#) fails with C++/CLI dependency #12345
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
Comments
Tagging subscribers to this area: @ViktorHofer |
Tagging subscribers to this area: @vitek-karas, @swaroop-sridhar |
I think this is because we don't allow loading "components" as self-contained. Is that right @jkoritzinsky ? |
Building a self-contained C++/CLI application is not supported, but I remember some discussions with the SDK team about if C++/CLI dependencies of a self-contained C# app should be supported. @wli3 do you remember where we landed on that? |
That is true. From the error code message $(Language) is evaluated to C++. It might be caused by running /t:publish in the folder. So all projects get published. Maybe try only publish the WPF project. |
Just for the record, I too am having the same problem. I hope this is a feature .net 5 will bring. For now I rely on the fact that my app directs the user to download and install the CLR at first run, wich is not ideal. A self-contained publish would be. |
I am experiencing this issue as well, and it would be great if Microsoft can just provide an official stance on the state of affairs, by clearly stating this limitation on their documentation, here are a few places to start: Your official documentation page on publishing self contained apps for various runtimes Blog entry touting the new C++/CLI project prowess which does not state this very important limitation It's a very clumsy experience for our end user when we now have to make them download the Runtime prior to our app installation. |
@wli3 Just to remove any ambiguity, attempting to self contained publish just the project which takes a dependency on the C++/CLI project as you appear to suggest does not work either. This is what I get
|
An other option would be to provide a .netcore runtime merge module I could include in my setups .msi, but I cant find those if they exists, anyone knows about that? This would be an alternative but the ideal would still be self contained deploy. |
@CrapuleJack my work around was to a WIX Bundle project to install the dependency, if you are using wix then here is a reference
Some resources around WIX Boostrapping |
@FunksMaName Thanks a lot for that, I will take a look at that for sure. Yes I am using wix, it is awesome. |
I moved this to dotnet/sdk as the issues seems to be around failures during publish. |
Will this be supported in .net 5? We have spent quite a long time porting a project over and have just hit this issue. |
Also had this problem attempting to create an MSIX install from Visual Studio. Previously our .Net framework WPF + CLI install worked fine, now we have upgraded to .net core 3.1 WPF +CLI and everything works fine apart from publishing to MSIX where we get: "C++/CLI projects targeting .NET Core cannot use SelfContained=true." |
Is fixing the standalone/self-contained C++/CLI issue on the roadmap for .NET 5? This is blocking our preferred update strategy. |
I think it's quite puzzling that this wasn't considered a ship-blocker for .NET Core 3.1 and .NET 5.0. There is no technical blocker to publishing a self-contained deployment that happens to include a C++/CLI dependency. Nuget packages that contain C++/CLI assemblies do not suffer from this SDK error message (since they are just seen as managed dependencies). This is in fact a workaround for this problem; people have to package up their component as a Nuget package and reference it from the other managed assemblies, which is a silly amount of work. It was mentioned above that this error exists to discourage people from trying to ship self-contained "components" where a native host loads a C++/CLI assembly as a native component. However, this is likely a very edge-case scenario, whereas shipping a fully managed EXE as self-contained that happens to also have a C++/CLI project in its dependency graph is an extremely common scenario, especially for people porting .NET framework apps to .NET core. This should be a well-tested scenario by the donet/SDK teams, but clearly it's not as it's blocked by this SDK error. All that really needs to be done here to fix the SDK is to prevent the error from being issued if the user has somehow declared they are not shipping a standalone "native component" DLL. For anyone that comes here looking for answers, a quick workaround is that you can add the following lines to your .vcxproj files after <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<!-- Disable the .NET SDK error that prevents using SelfContained=true -->
<Target Name="_CheckForLanguageAndFeatureCombinationSupport"></Target> |
Please fix this. |
Just faced this problem. Thought this would be fixed in .net 5.0. But sadly no. Also zhuman's advice helped. Thank you. |
Same problem |
Same problem as @Proudloaf with Windows App SDK app with C++ CLI dependency. App builds and run fine, but get errors when attempting to create app packages. Unfortunately @zhuman suggestion didn't work for me. However the error is now different: |
@mjfusa When the C# project has a target framework with Windows build specifiied (e.g.
This update then enables to build the app packaged, and run the packaged app from Visual Studio. This error happens with either Visual Studio 16.11.1 and .NET5.0, or 17.0.0 Preview 3.1 and .NET6.0 preview |
@damien78 Could you try setting the |
@dsplaisted Thanks, but no luck with this. Build successful, but same error when creating the packages |
@marcpopMSFT so this is moved to .NET7? In 6+ months? Very very sad |
This ticket has been an active and open ticket for 2 years already. It seems that this should take priority as it is an internal function of .NET Framework versus 'new features' in net7.0 |
It's not even clear that this will be released with .NET 7. I haven't seen evidence that it's included in the .NET 7 alpha releases. Just seems like another delaying tactic. I honestly don't know why this isn't being treated as a higher priority issue, would be good to understand the complexity in making a fix. |
I did some investigation of this, and it looks like it will probably be fixed by the following PRs:
We don't know for sure when we will be able to ship those, though. The problem has to do with the fact that the SelfContained property flows from the managed project to the referenced C++/CLI project. So there are some possible workarounds:
|
I'm facing the same issue while creating a dotnet 6 Microsoft store app with a C++/CLI interop library. I have tried a lot of workarounds in this thread and seem to go around in circles.
and some more things which lead to nothing. And I still get errors like I've created a minimum demo project with a C#, C++/CLI and packaging project. Maybe there is someone who can lead us in the right direction and get this demo deploying? The repository is located here: https://github.com/snandos/CPPCLI_Test |
Thanks, the trick is really to use msbuild and not dotnet for doing the publish. This did not work for fully for for us though, because we have C++/CLI libraries in our solution that shall be published.
Unfortunatly, the software crashed on start then, and in debug crash dumps we could see, that it crashed while loading C++/CLI dependencies. So, additionally, we set Then it did not crash any more. However, this is in the end not really "single-file" but at least the .NET6 is embedded in the .exe (which is now huge i.e. 150MB). It seems a bit unclear, what .NET6 those .dlls in the folder are using i.e. if they use the .NET6 from the .exe or if they use it from the system. |
I meet the error when tried to publish with cli/c++ project:
Is it possibile to specify RuntimeIdentifiers in cli/c++ project? |
Anybody tried this on dotnet 7 yet? |
Sadly still not working with dotnet 7. We have to wait at least another year.. |
This is some bulls**t. I'm tired of waiting for a fix for this, or even some kind of sign it's being worked on. At least some vendors know how to deal with production-critical software, I'd be better off switching to Java, at least then I could interop with C++ via GraalVM. |
To clarify, is this an issue with publishing a wapproj or is it still a broader issue with dotnet publish of c# apps with native dependencies? If the former (which was a repro project attached to this issue), we've routed this to the correct team now. Wappproj support should go through devcom as that's where they manage their customer feedback. If the latter, please provide a small example repro we can follow up on. |
It's the latter, it's a broader issue with publishing C# apps with C++/CLI project dependencies. As for reproduction of the issue, it's easy:
|
My issue beeing:
|
Problem still exists with .NET 8 |
I've successfully resolved the issue! Although the solution may have been discussed previously, I felt the explanations were not sufficiently clear, as well hard to find. ATTENTION! (The essence of the solution involves programmatically extracting your DLL to a temporary folder at runtime. This note is for those who prefer to skip learning about such a solution.) Solution: During runtime, hardcode your project to literally extract the DLL into a temporary folder of your choice, I recommend using the system's standard temporary directory and applying a GUID to assign a unique name to the DLL. Finally, employ .NET reflection to interact with the DLL that has been extracted, tip use visual studio to or dnspy to find the name of the various methods, types and more, that you will use from the dll. I realize this approach might not seem ideal to everyone, but it's the most effective solution I've found. I understand that this solution might be obvious to some people, nevertheless not to everyone thus I'm open to help "victims" of this issue further, if people are interested! Personally this problem has been bothering me a lot and I want to help everyone which is battling this issue :) |
🚧 @dsplaisted this is no longer true starting from .NET 8 : RuntimeIdentifier warning if self-contained is unspecified |
Same here. I have a solution, containing a C++/CLI project and I've run into this trying to publish a self-contained .NET 8 WinForms app. I'm on the latest Visual Studio. @zhuman suggestion to use _CheckForLanguageAndFeatureCombinationSupport in my C++/CLI project, worked. However, same as @damien78 I'm now blocked publishing my WAP project, to build an MSIX. I got the |
It's odd publishing from MSBuild works but publishing from Visual Studio does not with the same configuration. This error happens in Visual Studio but if I use an MSBuild project and target to publish, then everything works fine. |
@AMArostegui, did you have to enable the <Target Name="_CheckForLanguageAndFeatureCombinationSupport"></Target>
<Target Name="_CheckForLanguageAndPublishFeatureCombinationSupport"></Target> C:\Program Files\dotnet\sdk\8.0.303\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(588,11): error MSB4057: The target "ResolveLockFileCopyLocalFiles" does not exist in the
project. |
Thanks for this! This solved it for me, and I can now create the .appx package using the WAP project of my solution. BTW, I had no need for the following overriding:
|
I'm trying to port a WPF app (C#) to core 3.1, but it has a dependency on a C++/CLI managed wrapper on an unmanaged DLL. The dependency works, and I can build/run and publish as Framework Dependent, but I get a failure when I try to publish self contained. The error that I get in VS 16.5.4 is:
And the .tmp file it generates tells me:
Which is not helpful... The publish output however, had this buried in it:
That implies that there's no way to build this as a self contained application, which was part of the motivation for going to .net core with this app in the first place (zero dependency deployment). Is there a way to get this to work, or is it a bug?
The text was updated successfully, but these errors were encountered: