-
Notifications
You must be signed in to change notification settings - Fork 255
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
UAP - platform specific binaries not picked up from runtimes #1221
Comments
You need a ref library or anycpu (in your case you don't). I would probably use ref in your case with the x86 dll |
I've tried adding x86 dll in a following ways:
None of them worked for me. Would you mind posting an example showing me how should I add my x86 as a ref. |
There isn't any point in having a lib folder if you also have a win10-anycpu/lib folder. If that is all you need just put it in lib. If you need architecture specific implementation you can put that in a runtimes/win10-x86/lib/uap10.0 folder. So here are the two scenarios.
|
My dll will not compile as a As for scenario 2: <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="InjectReference" BeforeTargets="ResolveAssemblyReferences">
<ItemGroup Condition=" '$(Platform)' == 'x86' or '$(Platform)' == 'x64' or '$(Platform)' == 'ARM'">
<Reference Include="MySDK">
<HintPath>$(MSBuildThisFileDirectory)$(Platform)\MySDK.dll</HintPath>
</Reference>
</ItemGroup>
</Target>
</Project> I have tried adding |
The architecture is ignored by the compiler when creating an assembly reference. It's a load time concept. The loader will prefer an architecture specific reference if it exists. One trick you can use to produce an AnyCPU assembly is to use corflags to remove the architecture from your x86 assembly. EG: We produce stripped down reference assemblies for all of the .NET framework assemblies. You can see some examples of those in one my recent changes in corefx: dotnet/corefx@40723b7. We have numerous internal tools that can produce reference assemblies from implementation. @weshaggard @nguerrera do we have any public tools for creating reference assemblies or reference assembly source? |
I'm moving this issue to the discussions milestone, as there is no bug fix to be done here. @ericstj it would be nice to show this as one of our samples. |
@furmek the roslyn team is planning on adding support for reference assembly generation to the compiler. dotnet/roslyn#2184 |
@ericstj thank you, the I think at this point I'll describe my final solution so it can help someone else. First, description of MySDK: After building my solution I'm left with few files: NuGet package creation: next I pack my NuGet using following nuspec <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MySDK.UWP</id>
...
</metadata>
<files>
<file src="MySDKManaged.dll" target="lib\uap10.0\MySDKManaged.dll" /><!-- this one is changed by corflags command -->
<file src="..\SDK\bin\Debug\Win32\SDK.UAP\MySDKNative.winmd" target="lib\uap10.0\MySDKNative.winmd" />
<!-- x86 -->
<file src="..\SDK.UAP\bin\x86\Debug\MySDKManaged.dll" target="runtimes\win10-x86\lib\uap10.0\MySDKManaged.UAP.dll" />
<file src="..\SDK\bin\Debug\Win32\SDK\MySDKNative.winmd" target="runtimes\win10-x86\lib\uap10.0\MySDKNative.winmd" />
<file src="..\SDK\bin\Debug\Win32\SDK\MySDKNative.dll" target="runtimes\win10-x86\native\MySDKNative.dll" />
<file src="..\SDK\bin\Debug\Win32\SDK\MySDKNative.pri" target="runtimes\win10-x86\native\MySDKNative.pri" />
<!-- x64 -->
<file src="..\SDK.UAP\bin\x64\Debug\MySDKManaged.dll" target="runtimes\win10-x64\lib\uap10.0\MySDKManaged.UAP.dll" />
<file src="..\SDK\bin\Debug\x64\SDK\MySDKNative.winmd" target="runtimes\win10-x64\lib\uap10.0\MySDKNative.winmd" />
<file src="..\SDK\bin\Debug\x64\SDK\MySDKNative.dll" target="runtimes\win10-x64\native\MySDKNative.dll" />
<file src="..\SDK\bin\Debug\x64\SDK\MySDKNative.pri" target="runtimes\win10-x64\native\MySDKNative.pri" />
<!-- ARM -->
<file src="..\SDK.UAP\bin\ARM\Debug\MySDKManaged.dll" target="runtimes\win10-arm\lib\uap10.0\MySDKManaged.UAP.dll" />
<file src="..\SDK\bin\Debug\arm\SDK\MySDKNative.winmd" target="runtimes\win10-arm\lib\uap10.0\MySDKNative.winmd" />
<file src="..\SDK\bin\Debug\arm\SDK\MySDKNative.dll" target="runtimes\win10-arm\native\MySDKNative.dll" />
<file src="..\SDK\bin\Debug\arm\SDK\MySDKNative.pri" target="runtimes\win10-arm\native\MySDKNative.pri" />
</files>
</package> Package created like this can be added to UWP c# project and compiled for |
@furmek folks can compile UAP class libraries or windows runtime components for AnyCPU. Your solution will still work fine for those projects since they don't require implementation assets as they are not directly runnable. If someone were to build such a component, consuming your package, they could do so, then when they referenced that component from an application it would deploy the write bit-specific implementation for the app. One thing I notice about your package that you may or may not care about is consumption in C++ and JavaScript applications. I hadn't brought this up previously since we'd just been talking about dlls and not winmd. Since C++ and JS don't support project.json yet nuget won't use your runtime specific assets. Additionally JS will complain about the DLL being referenced. For the first problem I've been recommending that folks write targets files to address the issue. For the later the only solution I've come up with is to split the packages. It seems to be a shortcoming in the JS project system / inflexibility of nuget to provide language specific references. I'm actually working on some docs around these scenarios here: https://github.com/ericstj/nugetdocs/tree/ericstj/nuget3samples. Let's move the discussion over here. I hope to have a PR for nuget shortly. |
It doesn't seem possible at the moment to create a single nuget package that works across all UAP application languages (C#, VB, C++, JS) containing a WinRT component with x86, x64, and ARM binaries. The problem is caused by C# and VB using project.json while C++ and JS use packages.config. There seems to be no way (in a single package) to add build file(s) targeting the C++ and JS specifically (in order to add the necessary platform references). I've tried adding a "native" build file which works for C++, but there's no equivalent for JS. I've tried adding a uap10.0 build file with conditions for JS, but these seem to be ignored. Am I missing something? |
I believe you can create targets/props in the root build folder and then just condition the content of them to only apply for UWP apps. |
For anyone looking at this old thread, I've just added support for creating these kinds of advanced packages in my MSBuild.Sdk.Extras package: https://github.com/onovotny/MSBuildSdkExtras#per-runtimeidentifier |
Can anybody explain this to me "Architecture specific dll, requires a reference assembly since the "runtime" section is not used during compile."? I noticed that if I put assemblies only into runtimes section I cannot consume the package and build. What those assemblies are used for in this case? I expect when I reference a NuGet package with platform specific assemblies, those assemblies are used in compilation and in the result I would have a project built for particular platform. If they are not used this way how it would work? Will it use one set of assemblies for build and another for runtime? How it will use another set for runtime? Where it will take them from? I'm totally lost. |
My NuGet package contains .dll files that are build for specific platforms (arm, x86 and x64).
The project.lock.json file seems to be updating just fine but the project will build only in x86.
When trying to build in x64 or arm the runtimes/win10-[platform] is ignored - VS will complain about lib arhitecture:
The nupkg structure goes like this:
After installing my project.lock.json gets updated with following data:
I have tried to remove
compile
andruntime
from"UAP,Version=v10.0"
but after doing so, VS no longer can see namespaces in those libraries.MySDK does not have AnyCPU version and it is compiled specifically for UWP (former UAP).
Am I doing something wrong or is this a bug ?
The text was updated successfully, but these errors were encountered: