Dllimport generator build and test fixes (#59658)
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Wed, 6 Oct 2021 16:40:26 +0000 (09:40 -0700)
committerGitHub <noreply@github.com>
Wed, 6 Oct 2021 16:40:26 +0000 (09:40 -0700)
21 files changed:
eng/Versions.props
eng/generators.targets
eng/native/output-toolchain-info.cmake [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CloseHandle.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs
src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj
src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj
src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj
src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/AssemblyInfo.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj
src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/FunctionPointerTests.cs
src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.UnitTests.csproj
src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/DelegatesAndFunctionPointers.cs
src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj
src/libraries/tests.proj
src/samples/Directory.Build.props [new file with mode: 0644]
src/samples/Directory.Build.targets [new file with mode: 0644]
src/samples/DllImportGeneratorSample/DllImportGeneratorSample.csproj
src/samples/DllImportGeneratorSample/Program.cs

index bee1762..b7e09d4 100644 (file)
     <XunitPerformanceApiPackageVersion>1.0.0-beta-build0015</XunitPerformanceApiPackageVersion>
     <MicrosoftDiagnosticsToolsRuntimeClientVersion>1.0.4-preview6.19326.1</MicrosoftDiagnosticsToolsRuntimeClientVersion>
     <MicrosoftDiagnosticsNETCoreClientVersion>0.2.61701</MicrosoftDiagnosticsNETCoreClientVersion>
-    <DNNEVersion>1.0.23</DNNEVersion>
+    <DNNEVersion>1.0.26</DNNEVersion>
     <!--
       These are used as reference assemblies only, so they must not take a ProdCon/source-build
       version. Insert "RefOnly" to avoid assignment via PVP.
index 45f5cb6..e20fa99 100644 (file)
   <ItemGroup Condition="'@(EnabledGenerators)' != ''
                         and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'DllImportGenerator'))
                         and '$(IncludeDllImportGeneratorSources)' == 'true'">
-    <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj"  OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
-    <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedDllImportAttribute.cs" />
-    <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs" />
-    <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs" />
+    <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\DllImportGenerator\DllImportGenerator.csproj"  OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
+    <Compile Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\GeneratedDllImportAttribute.cs" />
+    <Compile Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\GeneratedMarshallingAttribute.cs" />
+    <Compile Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\ArrayMarshaller.cs" />
   </ItemGroup>
 
   <Target Name="ConfigureGenerators"
@@ -59,7 +59,7 @@
         <DefineConstants>$(DefineConstants);DLLIMPORTGENERATOR_INTERNALUNSAFE</DefineConstants>
     </PropertyGroup>
 
-    <MSBuild Projects="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj"
+    <MSBuild Projects="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\DllImportGenerator\DllImportGenerator.csproj"
              RemoveProperties="TargetFramework">
       <Output TaskParameter="TargetOutputs" PropertyName="DllImportGeneratorOutputPath" />
     </MSBuild>
diff --git a/eng/native/output-toolchain-info.cmake b/eng/native/output-toolchain-info.cmake
new file mode 100644 (file)
index 0000000..8eed988
--- /dev/null
@@ -0,0 +1,21 @@
+# Output the toolchain information required to create a command line that builds with the right rootfs as XML
+
+set (ADDED_COMPILE_OPTIONS)
+if (CMAKE_SCRIPT_MODE_FILE)
+  # add_compile_options and add_definitions can't be used in scripts,
+  # so override the implementations to append to a local property
+  macro(add_compile_options)
+    list(APPEND ADDED_COMPILE_OPTIONS ${ARGV})
+  endmacro()
+  macro(add_definitions)
+    list(APPEND ADDED_COMPILE_OPTIONS ${ARGV})
+  endmacro()
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/../common/cross/toolchain.cmake)
+
+message("<toolchain-info>")
+message("<target-triple>${TOOLCHAIN}</target-triple>")
+message("<linker-args>${CMAKE_SHARED_LINKER_FLAGS_INIT}</linker-args>")
+message("<compiler-args>${ADDED_COMPILE_OPTIONS}</compiler-args>")
+message("</toolchain-info>")
\ No newline at end of file
index 9c12510..0e4280b 100644 (file)
@@ -8,12 +8,9 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
-#if DLLIMPORTGENERATOR_ENABLED
-        [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)]
-        internal static partial bool CloseHandle(IntPtr handle);
-#else
+#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+                                                // Disabled since CloseHandle is a QCall in some scenarios and DllImportGenerator doesn't support QCalls.
         [DllImport(Libraries.Kernel32, SetLastError = true)]
         internal static extern bool CloseHandle(IntPtr handle);
-#endif
     }
 }
index 0564515..27eccfd 100644 (file)
@@ -15,13 +15,10 @@ internal static partial class Interop
         private const int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
         private const int ERROR_INSUFFICIENT_BUFFER = 0x7A;
 
-#if DLLIMPORTGENERATOR_ENABLED
-        [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "FormatMessageW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
-        private static unsafe partial int FormatMessage(
-#else
+#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+                                                // Disabled since FormatMessage is a QCall in some scenarios and DllImportGenerator doesn't support QCalls.
         [DllImport(Libraries.Kernel32, EntryPoint = "FormatMessageW", BestFitMapping = true, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
         private static extern unsafe int FormatMessage(
-#endif
             int dwFlags,
             IntPtr lpSource,
             uint dwMessageId,
@@ -29,6 +26,7 @@ internal static partial class Interop
             void* lpBuffer,
             int nSize,
             IntPtr arguments);
+#pragma warning restore DLLIMPORTGENANALYZER015
 
         /// <summary>
         ///     Returns a string message for the specified Win32 error code.
index 191cfd6..2c87776 100644 (file)
@@ -16,8 +16,8 @@ internal static partial class Interop
         internal static partial uint GetFullPathNameW(
 #else
         [DllImport(Libraries.Kernel32, BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
-        internal static extern uint GetFullPathNameW(
 #endif
+        internal static extern uint GetFullPathNameW(
             ref char lpFileName,
             uint nBufferLength,
             ref char lpBuffer,
index d37dc3c..90c999b 100644 (file)
@@ -15,10 +15,11 @@ internal static partial class Interop
         internal static partial uint GetLongPathNameW(
 #else
         [DllImport(Libraries.Kernel32, BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
-        internal static extern uint GetLongPathNameW(
 #endif
+        internal static extern uint GetLongPathNameW(
             ref char lpszShortPath,
             ref char lpszLongPath,
             uint cchBuffer);
+
     }
 }
index 9fbde72..7a2fed1 100644 (file)
@@ -1,5 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
+    <EnableDllImportGenerator>true</EnableDllImportGenerator>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
   </PropertyGroup>
   <ItemGroup>
index 87afaa0..b9739cb 100644 (file)
@@ -2,6 +2,7 @@
   <PropertyGroup>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <IncludeRemoteExecutor>true</IncludeRemoteExecutor>
+    <EnableDllImportGenerator>true</EnableDllImportGenerator>
     <!-- file locking can't be disabled on Windows -->
     <TargetFrameworks>$(NetCoreAppCurrent)-Unix</TargetFrameworks>
 
index 718551f..29bbd6f 100644 (file)
@@ -7,6 +7,7 @@
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <IncludeRemoteExecutor>true</IncludeRemoteExecutor>
     <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX</TargetFrameworks>
+    <EnableDllImportGenerator>true</EnableDllImportGenerator>
   </PropertyGroup>
 
   <ItemGroup>
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/AssemblyInfo.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..f95036d
--- /dev/null
@@ -0,0 +1,10 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using Xunit;
+
+// We build the libraries tests in CI once per target OS+Arch+Configuration, but we share it between runtime test runs.
+// As a result, we need to exclude the Mono run here since we build the tests once for CoreCLR and Mono for desktop test runs.
+// We should switch this to another mechanism in the future so we don't submit a work item of this assembly that skips every test
+// for Mono-on-Desktop-Platforms test runs.
+[assembly:ActiveIssue("https://github.com/dotnet/runtime/issues/59815", TestRuntimes.Mono)]
index 887a041..351241b 100644 (file)
@@ -1,6 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
+    <TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
     <IsPackable>false</IsPackable>
     <LangVersion>Preview</LangVersion>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
index f083c24..87332f1 100644 (file)
@@ -13,7 +13,7 @@ namespace DllImportGenerator.IntegrationTests
     {
         public partial class FunctionPointer
         {
-            [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_after_gc")]
+            [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_managed_callback_after_gc")]
             public static unsafe partial void InvokeAfterGC(delegate* <void> cb);
 
             [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_after_gc")]
@@ -22,7 +22,7 @@ namespace DllImportGenerator.IntegrationTests
             [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_after_gc")]
             public static unsafe partial void InvokeAfterGC(delegate* unmanaged[Stdcall]<void> cb);
 
-            [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_blittable_args")]
+            [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_managed_callback_blittable_args")]
             public static unsafe partial int InvokeWithBlittableArgument(delegate* <int, int, int> cb, int a, int b);
 
             [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_blittable_args")]
index 89b2d19..6186cea 100644 (file)
@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
+    <TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
     <IsPackable>false</IsPackable>
     <LangVersion>Preview</LangVersion>
     <Nullable>enable</Nullable>
index 50abe95..8925bcd 100644 (file)
@@ -23,10 +23,31 @@ namespace NativeExports
             fptr();
         }
 
+        [UnmanagedCallersOnly(EntryPoint = "invoke_managed_callback_after_gc")]
+        public static void InvokeManagedCallbackAfterGCCollect(void* fptr)
+        {
+            // We are at the mercy of the GC to verify our delegate has been retain
+            // across the native function call. This is a best effort validation.
+            for (int i = 0; i < 5; ++i)
+            {
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+            }
+
+            // If the corresponding Delegate was collected, the runtime will rudely abort.
+            ((delegate*<void>)fptr)();
+        }
+
         [UnmanagedCallersOnly(EntryPoint = "invoke_callback_blittable_args")]
         public static int InvokeCallbackWithBlittableArgument(delegate* unmanaged<int, int, int> fptr, int a, int b)
         {
             return fptr(a, b);
         }
+
+        [UnmanagedCallersOnly(EntryPoint = "invoke_managed_callback_blittable_args")]
+        public static int InvokeManagedCallbackWithBlittableArgument(void* fptr, int a, int b)
+        {
+            return ((delegate*<int, int, int>)fptr)(a, b);
+        }
     }
 }
index 00a8f53..c93a8ac 100644 (file)
@@ -7,6 +7,9 @@
     <EnableDynamicLoading>true</EnableDynamicLoading>
     <DnneAddGeneratedBinaryToProject>true</DnneAddGeneratedBinaryToProject>
     <DnneGenRollForward>Major</DnneGenRollForward>
+    <!-- To integrate with DNNE's architecture calculation, we need to set the RID for this project. -->
+    <RuntimeIdentifier>$(OutputRid)</RuntimeIdentifier>
+    <AppHostRuntimeIdentifier>$(OutputRid)</AppHostRuntimeIdentifier>
   </PropertyGroup>
 
   <ItemGroup>
     <ProjectReference Include="..\SharedTypes\SharedTypes.csproj" />
   </ItemGroup>
 
+  <Target Name="GetLinuxCrossBuildArgumentsForDNNE"
+          Condition="'$(CrossBuild)' == 'true' and (
+            '$(TargetOS)' == 'Linux' or
+            '$(TargetOS)' == 'NetBSD' or
+            '$(TargetOS)' == 'FreeBSD' or
+            '$(TargetOS)' == 'illumos' or
+            '$(TargetOS)' == 'Solaris')">
+    <PropertyGroup>
+      <NativeCompiler>$(Compiler)</NativeCompiler>
+      <NativeCompiler Condition="'$(NativeCompiler)' == ''">clang</NativeCompiler>
+    </PropertyGroup>
+
+    <Exec Command="bash -c 'source &quot;$(RepositoryEngineeringDir)/common/native/init-compiler.sh&quot; &quot;$(RepositoryEngineeringDir)/common/native&quot; $(TargetArchitecture) $(NativeCompiler) &amp;&amp; echo $CC '"
+          EchoOff="true"
+          ConsoleToMsBuild="true"
+          StandardOutputImportance="Low">
+      <Output TaskParameter="ConsoleOutput" PropertyName="DnneCompilerCommand" />
+    </Exec>
+    <Exec Command="cmake -P &quot;$(RepositoryEngineeringDir)/native/output-toolchain-info.cmake&quot;"
+          EchoOff="true"
+          ConsoleToMsBuild="true"
+          StandardOutputImportance="Low"
+          EnvironmentVariables="TARGET_BUILD_ARCH=$(TargetArchitecture)">
+      <Output TaskParameter="ConsoleOutput" PropertyName="CrossTargetXml" />
+    </Exec>
+
+    <XmlPeek XmlContent="$(CrossTargetXml)" Query="toolchain-info/target-triple/text()">
+      <Output TaskParameter="Result" PropertyName="TargetTriple" />
+    </XmlPeek>
+    <XmlPeek XmlContent="$(CrossTargetXml)" Query="toolchain-info/linker-args/text()">
+      <Output TaskParameter="Result" PropertyName="DnneLinkerUserFlags" />
+    </XmlPeek>
+    <XmlPeek XmlContent="$(CrossTargetXml)" Query="toolchain-info/compiler-args/text()">
+      <Output TaskParameter="Result" PropertyName="DnneCompilerUserFlags" />
+    </XmlPeek>
+
+    <PropertyGroup>
+      <CommonToolchainArgs>--target=$(TargetTriple) --gcc-toolchain=$(ROOTFS_DIR)/usr --sysroot=$(ROOTFS_DIR)</CommonToolchainArgs>
+      <DnneLinkerUserFlags>$(CommonToolchainArgs) $(DnneLinkerUserFlags.Replace(';',' '))</DnneLinkerUserFlags>
+      <DnneCompilerUserFlags>$(CommonToolchainArgs) $(DnneCompilerUserFlags.Replace(';',' '))</DnneCompilerUserFlags>
+    </PropertyGroup>
+  </Target>
+
+  <Target Name="GetAppleCrossBuildArgumentsForDNNE"
+          Condition="'$(TargetOS)' == 'OSX' or
+            '$(TargetOS)' == 'MacCatalyst' or
+            '$(TargetOS)' == 'iOS' or
+            '$(TargetOS)' == 'iOSSimulator' or
+            '$(TargetOS)' == 'tvOS' or
+            '$(TargetOS)' == 'tvOSSimulator'">
+    <PropertyGroup Condition=" '$(TargetOS)' == 'MacCatalyst'">
+      <TargetTriple Condition="'$(TargetArchitecture)' == 'arm64'">arm64-apple-ios14.2-macabi</TargetTriple>
+      <TargetTriple Condition="'$(TargetArchitecture)' == 'x64'">x86_64-apple-ios13.5-macabi</TargetTriple>
+    </PropertyGroup>
+    <PropertyGroup Condition="'$(TargetOS)' == 'OSX'">
+      <TargetTriple Condition="'$(TargetArchitecture)' == 'arm64'">arm64-apple-macos11</TargetTriple>
+      <TargetTriple Condition="'$(TargetArchitecture)' == 'x64'">x86_64-apple-macos10.13</TargetTriple>
+      <XCodeSdkName>macosx</XCodeSdkName>
+    </PropertyGroup>
+
+    <Error Condition="'$(TargetTriple)' == ''" Text="A target triple was not specified for the native components build. Update the 'GetAppleCrossBuildArgumentsForDNNE' target to specify a triple." />
+    <Error Condition="'$(XCodeSdkName)' == ''" Text="The name of the XCode SDK for the target platform, as passed to xcrun to locate the sdk, must be specified." />
+
+    <!-- xcrun is used to locate the XCode SDKs and tools within them. See the xcrun manpage for usage information. -->
+    <Exec Command="xcrun --sdk $(XCodeSdkName) --show-sdk-path"
+          EchoOff="true"
+          ConsoleToMsBuild="true"
+          StandardOutputImportance="Low">
+      <Output TaskParameter="ConsoleOutput" PropertyName="SysRootIncludePath" />
+    </Exec>
+
+    <Exec Command="xcrun --sdk $(XCodeSdkName) --find clang"
+          EchoOff="true"
+          ConsoleToMsBuild="true"
+          StandardOutputImportance="Low">
+      <Output TaskParameter="ConsoleOutput" PropertyName="DnneCompilerCommand" />
+    </Exec>
+
+    <PropertyGroup>
+      <DnneLinkerUserFlags>-target $(TargetTriple)</DnneLinkerUserFlags>
+      <DnneCompilerUserFlags>-isysroot &quot;$(SysRootIncludePath)&quot; -target $(TargetTriple)</DnneCompilerUserFlags>
+    </PropertyGroup>
+  </Target>
+
+  <Target Name="GetBuildArgumentsForDNNE"
+          DependsOnTargets="ResolveFrameworkReferences;
+                            GetLinuxCrossBuildArgumentsForDNNE;
+                            GetAppleCrossBuildArgumentsForDNNE"
+          BeforeTargets="DnneBuildNativeExports">
+    <PropertyGroup>
+      <DnneNetHostDir>$([System.IO.Path]::GetDirectoryName('$(AppHostSourcePath)'))</DnneNetHostDir>
+    </PropertyGroup>
+  </Target>
 </Project>
index aefca41..05d56f0 100644 (file)
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Transactions.Local\tests\System.Transactions.Local.Tests.csproj" />
   </ItemGroup>
 
+  <ItemGroup Condition="'$(TargetsMobile)' == 'true'">
+    <!-- DllImportGenerator runtime tests depend on DNNE, which does not support mobile platforms. -->
+    <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\DllImportGenerator.Tests\DllImportGenerator.Tests.csproj" />
+  </ItemGroup>
+
+  <ItemGroup Condition="'$(TargetOS)' == 'windows' and '$(TargetArchitecture)' == 'arm'">
+    <!-- DllImportGenerator runtime tests depend on DNNE, which does not support Windows ARM32 as we don't officially support it. -->
+    <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\DllImportGenerator.Tests\DllImportGenerator.Tests.csproj" />
+  </ItemGroup>
+
+  <ItemGroup Condition="'$(TargetOS)' == 'FreeBSD'">
+    <!-- DllImportGenerator runtime tests build depends pulling down a pre-built nethost binary, which is not available for FreeBSD. -->
+    <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\DllImportGenerator.Tests\DllImportGenerator.Tests.csproj" />
+  </ItemGroup>
+
   <ItemGroup Condition="'$(TargetOS)' == 'Windows' and '$(RuntimeFlavor)' == 'Mono' and '$(RunDisabledMonoTestsOnWindows)' != 'true'">
     <!-- Issue: https://github.com/dotnet/runtime/issues/53281 -->
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.WebSockets.Client\tests\System.Net.WebSockets.Client.Tests.csproj" />
diff --git a/src/samples/Directory.Build.props b/src/samples/Directory.Build.props
new file mode 100644 (file)
index 0000000..4590be1
--- /dev/null
@@ -0,0 +1,8 @@
+<Project>
+  <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />
+
+  <PropertyGroup>
+    <EnableDefaultItems>true</EnableDefaultItems>
+    <UseLocalTargetingRuntimePack>true</UseLocalTargetingRuntimePack>
+  </PropertyGroup>
+</Project>
diff --git a/src/samples/Directory.Build.targets b/src/samples/Directory.Build.targets
new file mode 100644 (file)
index 0000000..74fb272
--- /dev/null
@@ -0,0 +1,5 @@
+<Project>
+  <Import Project="$(RepositoryEngineeringDir)targetingpacks.targets" />
+
+  <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />
+</Project>
index f42621f..32bd062 100644 (file)
@@ -16,6 +16,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj"  OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
     <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\tests\Ancillary.Interop\Ancillary.Interop.csproj" />
     <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\tests\TestAssets\NativeExports\NativeExports.csproj" />
   </ItemGroup>
index 6e2f1de..4a1c833 100644 (file)
@@ -1,9 +1,12 @@
-using System;
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
 using System.Runtime.InteropServices;
 
 namespace Demo
 {
-    partial class NativeExportsNE
+    internal static partial class NativeExportsNE
     {
         public const string NativeExportsNE_Binary = "Microsoft.Interop.Tests." + nameof(NativeExportsNE);
 
@@ -17,9 +20,9 @@ namespace Demo
         public static partial void Sum(int a, ref int b);
     }
 
-    class Program
+    internal static class Program
     {
-        static void Main(string[] args)
+        public static void Main(string[] args)
         {
             int a = 12;
             int b = 13;