Giter Club home page Giter Club logo

vcrt-forwarders's Introduction

VCRT Forwarders Preview

This project contains App-local DLLs that forward to runtime DLLs that are required to run Visual C++ applications and components. The runtime DLLs being forwarded to should already be installed on a given machine, this can be done using the Visual C++ Redistributable Packages.

NuGet Package

The NuGet package Microsoft.VCRTForwarders.140 can be found here.

Referencing the package will include the appropriate version of the forwarders on supported architectures based on the CRT (debug / release) in use in the component project. For projects using custom debug configurations and referencing the component DLL directly rather than via project (i.e C++ applications), the VCRTForwarders-IncludeDebugCRT property can be set to true for that configuration to ensure inclusion of the debug CRT forwarders.

Sample usage

You can find samples of C++ and C# apps using the forwarders here.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Reporting Security Issues

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) at <[email protected]>. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter.

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License.

vcrt-forwarders's People

Contributors

dfields-msft avatar dhowett avatar huios avatar majaeger avatar manodasanw avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar stephenhodgson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vcrt-forwarders's Issues

AddDllDirectory fails when dlls/c# files are placed in a unity package compared to in the project Assets folder

@dfields-msft

We should do a more robust search to try and locate dlls in a unity package folder. Right now it appears we only look for dlls in the Unity project's assets folder.

if (AddDllDirectory(dllDirectory) == 0)

This causes dlls to fail to load when they are available to the project. This change will be needed if VCRTFowarders is distributed through a unity package.

Consider linking with /NOENTRY option

As these DLLs have no code on their own, I think the standard CRT initialization and termination routines aren't needed. The gains on performance and file size will be negligible but I believe this project configuration change may keep things tidier. For example, the api-ms-win-crt-*.dll libraries from the Universal CRT (for Windows versions before Windows 10) are pure forwarders to Ucrtbase.dll and they haven't an entry point.

There is a dllmain.cpp file at 140_release\vcrt_fwd_x64_release\msvcp140_app, but it isn't even referenced by any project file.

VCRT Forwarders Initializer breaks iOS/Mac builds

The call here fails for me in a Mac Unity Editor (2019.2.*):

IntPtr modulePtr = LoadLibraryExW(moduleName, IntPtr.Zero, LOAD_LIBRARY_SEARCH_USER_DIRS);

It seems that these initializer c# scripts should only run in UNITY_EDITOR_WIN environments. Wrapping the InitVCRTForwarders.cs file content in UNITY_EDITOR_WIN ifdefs unblocked iOS builds for me. Note: this affects all other projects that follow this model of calling LoadLibraryExW in the Unity editor, such as Microsoft.MixedReality.QR

When this error occurs, it may not necessarily result in a formal Unity build failure. In my case, it does prevent other prebuild/postbuild scripts from running. This causes things like Azure Spatial Anchors that copies Podfiles into generate iOS project folders to fail, causing the iOS build to fail in xcode.

Binaries are not automatically copied to the output directory for managed projects

I'm using this package to supplement a native binary built for UWP so it can be used in non-UWP projects as well. This works fine if the non-UWP project is also native, but when I consume this package (directly or indirectly) from a managed project, the binaries do not get copied to the output directory; I have to add manual build steps to do this. Then everything works great! Can this package be updated to make this happen auto-magically?

Will VCRT forwarders always point to DLLs included in working directory for Unpackaged Win32 applications?

Our team's product is an unpackaged Win32 desktop application that already includes the necessary VCRT DLLs in the EXE's local installation directory, so that we do not have to rely on users already having the corresponding VC++ Redistributable Package installed on their machine.

We are introducing a dependency that requires the use of VCRT forwarders, and we are wondering: Is it guaranteed that these forwarders will try pointing to the VCRT DLLs already included in our application's working directory first before searching for other locations? We are concerned about cases where these forwarders might throw an error if they cannot find the DLLs from a Redistributable package despite the fact that we already include them with our own application's installation.

In our working prototype, it seems that the forwarders always point to our own DLLs (based on the DLL list provided by Process Explorer), which is the desired behavior for our use case. But I wanted to ask here to get an expert opinion on whether or not this behavior 100% reliable.

Any clarification or insight you all can offer would be greatly appreciated. Cheers!

What is the point of this repository?

What the title says, really. This repo doesn't help much with true app-local (portable xcopy-deploy) deployment of the CRT, as this repo contains no actual code, only export forwarders. When I need to do true portable CRT deployment, I copy the applicable DLLs out of the VC\Redist folder in my VS install.

Besides, IIRC the *_app.dll files contain only UWP-compatible APIs. This would make the stubs in this repository and the real implementations being forwarded to incompatible, potentially causing Store submission failure if used. Some clarification on how this code is useful would be appreciated. Thanks!

All libraries in this repo should have VERSIONINFO resources

Some deployment technologies use file version checks to determine whether they need to update files on disk. Since these are in fact DLLs that get shipped alongside applications that may be deploying outside of MSIX, they should have version resources.

Proposal

Each DLL produced via this project's build system contains a VERSIONINFO resource that mirrors the VERSIONINFO resource of the specific version of the specific DLL it is pretending to be.

v1.0.6 regression: cannot build a solution project in isolation, ProjectReferenceWithConfiguration undefined

Prior to v1.0.6, a project with a VCRT forwarders reference could be built in isolation. Now, that fails because ProjectReferenceWithConfiguration is not defined.

Repro
Clone cswinrt repo
Run build.cmd
Attempt to build sample project alone:
c:\git\cswinrt\WinUIDesktopSample>msbuild /bl /p:platform=x64;configuration=release;solutiondir=c:\git\cswinrt\ WinUIDesktopSample.csproj

Expected
build succeeds

Actual
build fails:
C:\Users\scott.nuget\packages\microsoft.vcrtforwarders.140\1.0.6\build\netcoreapp2.0\Microsoft.VCRTForwarders.140.targets(61,5): error MSB4044
: The "UseDebugCRT" task was not given a value for the required parameter "Configuration". [C:\git\cswinrt2\WinUIDesktopSample\WinUIDesktopSample
.csproj]

Build break when compiling WAP project

When adding a reference to the VCRT forwarders in a WAP project, the Release build will fail with this error:

\packages\microsoft.vcrtforwarders.140\1.0.6\build\netcoreapp2.0\Microsoft.VCRTForwarders.140.targets(61,5): error MSB4044: The "UseDebugCRT" task was not given a value for the required parameter "Configuration". [MyApp.csproj]

This is a workaround for this problem:

    <Target Name="_FixUpProjectConfigurations"
        BeforeTargets="ResolveVCRTForwarderReferences"
        Condition="'@(ProjectReferenceWithConfiguration)' != '' And '$(VCRTForwarders-IncludeDebugCRT)' == ''">

        <ItemGroup>
            <_SavedProjectReferenceWithConfiguration Include="@(ProjectReferenceWithConfiguration)">
                <Configuration>$(Configuration)</Configuration>
                <Platform>$(Platform)</Platform>
            </_SavedProjectReferenceWithConfiguration>
            <ProjectReferenceWithConfiguration Remove="@(ProjectReferenceWithConfiguration)" />
            <ProjectReferenceWithConfiguration Include="@(_SavedProjectReferenceWithConfiguration)" />
        </ItemGroup>
    </Target>

Attached msbuild log.
wap.Release.binlog.zip

"debug"/"release" folder not honored by .NET CLI

.NET CLI (or NuGet) doesn't care about the "debug"/"release" folder names and always copies libraries in both configurations.

Background: I'm building an non-packaged app which hosts a UWP control.

Steps to reproduce

dotnet new console
dotnet add package Microsoft.VCRTForwarders.140 --version 1.0.6
dotnet publish -c Release -r win10-x64 -p:Platform=x64

Expected behaviors

Only release libraries are copied to the output directory.

Actual behaviors

Both debug and release libraries are copied to the output directory.

No PDBs included for the DLLs

This makes it impossible to run binskim over them, which is a requirement to use nugets in various Microsoft corp repos. I think if instead /noentry was used (to remove all the code from them) that might be sufficient instead of publishing the PDBs. The PDBs are also not on either Microsoft symbol server.

Make project forkable/buildable

vcxproj files should invoke the cmd script used to generate the linker forwarding records so that anyone can fork this repo and build.

Using a custom Configuration doesn't work with VCRT Forwarders

In the targets file for VCRT Forwarders, it checks for $(Configuration) == Release or Debug, explicitly by name. This means that if i want to add a custom Configuration to my solution (like Debug-WithExtraStuff), I don't get the right files binplaced with the ReferenceLocalCopyPaths.

Please add some other property that can allow me to opt-in to the Debug/Release steps of the VCRT forwarder targets. As an example, this line in the targets:

<ItemGroup Condition="'$(Configuration)' == 'Debug' And ('$(Platform)' == 'Win32' Or '$(Platform)' == 'x86')">

Could change to this:

<ItemGroup Condition="'($(Configuration)' == 'Debug' Or $(VCRTForwarders-Configuration) == 'Debug') And ('$(Platform)' == 'Win32' Or '$(Platform)' == 'x86')">

Then I could set that property in my custom configuration to get the same behavior as Debug or Release.

ARM32

The nuget package lacks an ARM32 build. Is there a reason for this omission?

Build fails on Azure pipeline when VCRTForwarders are added as nuget and there is anothe project reference.

We have a project A, .NET framework net5.0-windows10.0.19041.0
Platform x64
We are referencing a nuget package of Project B wihich has a reference to VCRTForwarders.
if we add any project reference to project A. We are getting the following error in build pipeline
..........nuget\packages\microsoft.vcrtforwarders.140\1.0.7\build\netcoreapp2.0\Microsoft.VCRTForwarders.140.targets(61,5): error MSB4801: The task factory "CodeTaskFactory" is not supported on .NET core version of MSBuild....................

..........nuget\packages\microsoft.vcrtforwarders.140\1.0.7\build\netcoreapp2.0\Microsoft.VCRTForwarders.140.targets(61,5): error
MSB4175: The task factory "CodeTaskFactory" could not be loaded from the assenbly...........................

We will be very grateful if this issue is fixed, it will solve a couple of issues for us.

Thank you!

Using the publish option in Visual Studio does not copy the dlls to the target directory

I have a .net core 3.1 application using XAML islands. The reference to this package is automatically added when referencing the xaml host nuget package from the windows toolkit. Building the project from Visual Studio works fine (the dlls are copied into the output folder), but using the publish functionality does not copy the dlls to the target folder.

The recursive MSBuild task UseDebugCRT forces incorrect solution build

There is a task, UseDeubgCRT, that forces the evaluation of a project file in the wrong context.

That context is missing the SolutionDir global property because it is using ProjectCollection.LoadProject with a hardcoded set of properties.

This causes any projects that <Import> files based on SolutionDir to fail to load.

Using MSBuild programmatically in this way, you must use:

var project = ProjectCollection.GlobalProjectCollection.GetLoadedProjects(projectPath).FirstOrDefault();

Binaries are set to Debug/Release configurations instead of _DEBUG macro

I have found an issue in Microsoft.VCRTForwarders.140. It sets up debug binaries in Debug configuration and release ones in Release. But actually Unreal uses release c runtime in Debug and also Unreal can have more configurations then Release and Debug. To cope with that Visual Studio uses special macro _DEBUG. If _DEBUG is defined then MSVS uses debug c runtime and release c runtime if it isn’t. Can you change Microsoft.VCRTForwarders.140.targets to follow that rule?

PublishSingleFile error on .NET Core 3.0 Preview 8 "Invalid input specification: Found multiple entries with the same BundleRelativePath"

Hello.
I got error dotnet publish with vcrt-forwarders.
Is this dotnet/core-setup bug?

[environment]
.NET Core 3.0 Preview 8
Microsoft.VCRTForwarders.140 Version=1.0.1-rc
csproj has "PublishSingleFile" element
Console app

[command]
dotnet publish ConsoleApp1.csproj /p:PublishProfile=\PublishProfiles\FolderProfile.pubxml

[error message]

C:\Program Files (x86)\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(807,5): error MSB4018: "GenerateBundle" task failed unexpectedly. [	ConsoleApp1\ConsoleApp1.csproj]
C:\Program Files (x86)\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(807,5): error MSB4018: System.ArgumentException: Invalid input specification: Found multiple entries with the same BundleRelativePath [	ConsoleApp1\ConsoleApp1.csproj]
C:\Program Files (x86)\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(807,5): error MSB4018:    at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList`1 fileSpecs) [	ConsoleApp1\ConsoleApp1.csproj]
C:\Program Files (x86)\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(807,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateBundle.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs:line 35 [	ConsoleApp1\ConsoleApp1.csproj]
C:\Program Files (x86)\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(807,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 38 [	ConsoleApp1\ConsoleApp1.csproj]
C:\Program Files (x86)\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(807,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [	ConsoleApp1\ConsoleApp1.csproj]
C:\Program Files (x86)\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(807,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [	ConsoleApp1\ConsoleApp1.csproj]

[Sample csproj]
ConsoleApp1.zip

.NET RID not supported

It would be good if we don't need to explicitly specify <Platform> if it has been implied by <RuntimeIdentifier>/<PlatformTarget>.

dotnet publish -c Release -r win10-x64

-or-

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
  </PropertyGroup>

</Project>

It's valid to add a project reference from a Any CPU project to a x64 one.

exe> dotnet add reference ..\lib\
Reference `..\lib\lib.csproj` added to the project.

exe> dotnet build
  Determining projects to restore...
  lib -> lib\bin\x64\Debug\net5.0\lib.dll
  exe -> exe\bin\Debug\net5.0\exe.dll

Missing msvcp140_codecvt_ids_app.dll

The MSVCP satellite DLL msvcp140_codecvt_ids_app.dll, first released in Visual Studio 2019 16.2, is not covered by the VCRTForwarders nuget package.

This is not an issue blocking me, I just noticed it was missing.

VCRTForwarder binaries are not accessible in Unity Standalone projects

There are two problems which prevent the VCRTForwarder binaries from being accessible in Unity Standalone projects:

  1. The .meta file designates the binaries as AnyCpu rather than denoting the correct architecture, so they are placed into the wrong subdirectory in the application data folder.
  2. The application data folder paths are not part of the default library search path, so the initialization scripts need to be updated to call AddDllDirectory in Standalone configurations as they do in Editor configurations.

Forwarder binaries are included in the app package for CppWinrt apps if the forwarders nuget package is installed

We have a nuget package (Microsoft.MixedReality.QR) that supports both packaged and non-packaged apps. Our package has a dependency on the Microsoft.VCRTForwarders package to support the non-packaged scenarios, but when including our package in a CppWinrt app, the forwarders are included in the appx output, which causes our binary to fail to load on certain platforms (HoloLens) due to missing dependencies.

Impossible to load VCRT Forwarders if strict Control Flow Guard is enabled

int main()
{
#ifdef _CONTROL_FLOW_GUARD
	PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY cfg_policy;
	if (GetProcessMitigationPolicy(GetCurrentProcess(), ProcessControlFlowGuardPolicy, &cfg_policy, sizeof(cfg_policy)))
	{
		cfg_policy.StrictMode = true;
		SetProcessMitigationPolicy(ProcessControlFlowGuardPolicy, &cfg_policy, sizeof(cfg_policy));
	}
#endif

    // do something that requires loading the VCRT forwarders, like initializing WinUI.
}

When building the above code with /cf:guard, the following error occurs when trying to load the forwarder DLLs.

Exception thrown at 0x00007FFC0160467C (KernelBase.dll) in TranslucentTB.exe: WinRT originate error - 0x80070679 : 'The specified image file was blocked from loading because it does not enable a feature required by the process: Control Flow Guard.'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.