dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.12k stars 222 forks source link

Compile PInvoke #267

Closed HeikoStudt closed 8 years ago

HeikoStudt commented 8 years ago

Hello,

I've run into issues compiling PInvoke:

  1. (probably) no project can reference their CodeGenerationAttributes or WIndows.Core

Warning The project 'CodeGenerationAttributes' cannot be referenced. Warning The project 'CodeGenerationAttributes.Profile111' cannot be referenced. Warning The referenced component 'Windows.Core' could not be found.

Therefore, it cannot generate code and I get errors like

Error CS1615 Argument 4 may not be passed with the 'ref' keyword Kernel32.Profile111 C:\Temp\PInvoke\pinvoke\src\Kernel32.Shared\Kernel32.Helpers.cs 207 Error CS1061 'DbgHelp.LOADED_IMAGE' does not contain a definition for 'FileHeader_IntPtr' and no extension method 'FileHeader_IntPtr' accepting a first argument of type 'DbgHelp.LOADED_IMAGE' could be found (are you missing a using directive or an assembly reference?) DbgHelp.Tests C:\Temp\PInvoke\pinvoke\src\DbgHelp.Tests\DbgHelpFacts.cs 15

  1. If I try to open "Properties" of CodeGenerationAttributes or Windows.Core I get a JSON error:

An error occurred trying to load the page. Additional text found in JSON string after finishing deserializing object.

  1. Please add into Contribution.md that you need the Nuproj extension :-)

I am using Visual Studio 2015 on Win10 having Resharper suspended

MFG (Sincerly)

AArnott commented 8 years ago

The JSON error you see in the project designer is a bug in the project system. Nothing we can do about that except ignore it. The project system is also responsible for the mistaken warning about the project references. The references are fine. Please ignore the warnings in the error list. NuProj is only required for building packages within VS. You can build the whole thing from the command line using build.ps1 without NuProj installed.

AArnott commented 8 years ago

Thanks for your report.

HeikoStudt commented 8 years ago

Thank you for the fast respond and adding the hint. Ok, I will ignore the warnings and Json error. :-) But why does the code generation not work or at least the project not compile for me?

Starting the build.ps1, I get the same errors:

[...]

CodeGeneration.Debugging -> C:\Temp\BeckyPluginTest\PInvoke\pinvoke\src\CodeGeneration.Debugging\bin\Debug\CodeGeneration.Debugging.exe Windows.Core -> C:\Temp\BeckyPluginTest\PInvoke\pinvoke\bin\Debug\Profile92\PInvoke.Windows.Core.dll Shared\Kernel32.Helpers.cs(150,72): error CS1615: Argument 4 may not be passed with the 'ref' keyword [C:\Temp\BeckyPluginTest\PInvoke\pinvoke\src\Kernel32\Kernel32.csproj] [...]

If you need anything, please give me a hint what to look at. :-)

MFG (sincerly)

AArnott commented 8 years ago

@HeikoStudt do you have this file on your computer? "%ProgramFiles(x86)%\MSBuild\14.0\Imports\Microsoft.Common.Props\ImportBefore\Microsoft.NuGet.ImportBefore.props"

HeikoStudt commented 8 years ago

10.03.2016 21:12 873 Microsoft.NuGet.ImportBefore.props

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <NuGetProps Condition="'$(NuGetProps)'==''">$(MSBuildExtensionsPath)\Microsoft\NuGet\Microsoft.NuGet.props</NuGetProps>
  </PropertyGroup>
  <Import Condition="Exists('$(NuGetProps)')" Project="$(NuGetProps)" />
</Project>

MFG (Sincerly)

AArnott commented 8 years ago

Then I'm out of ideas. We have the CI machine and many others saying there's no problem with build here. I'm not sure if you're missing some subtle dependency that the rest of us have or not -- but I don't think I can help you at this point.

HeikoStudt commented 8 years ago

Yeah, I have got the first layer of the problem! :-) Several Project.json files lack the dependency to "CodeGeneration.Roslyn": BCrypt, BCrypt.Profile111, DbgHelp, DbgHelp.Profile111, Kernel32, Kernel32.Profile111 Currently, I have those Project.json files with open changes, adding the 0.1.48-alpha-gaa3f482974 Version and everything but one test Project is building.

As I do not understand the process of the code generation build completely, you could help out to tell me, whether these dependencies would be added automatically somehow or why they are missing here only.

MFG (sincerly)

AArnott commented 8 years ago

CodeGeneration.Roslyn is brought into these projects via transitive dependency propagation. In the project.json world, all dependencies of a project become the dependencies of projects that reference that project. You can see this after running .\build.ps1 -restore and inspecting the project.lock.json file of BCrypt, for example. You'll see CodeGeneration.Roslyn is in fact listed. My guess is you're not using this script to restore packages (and/or you haven't disabled automatic package restore on build in VS) such that the nuget restore you're running doesn't properly propagate these dependencies.

HeikoStudt commented 8 years ago

The visual Studio is practically plain vanilla now; I have installed anew. In Nuget/General both downloading and auto-check are enabled.

The BCyrpt Project.lock.json is the following (after build.cmd -restore): { "locked": false, "version": 1, "targets": { ".NETPortable,Version=v4.0,Profile=Profile92": {} }, "libraries": {}, "projectFileDependencyGroups": { "": [], ".NETPortable,Version=v4.0,Profile=Profile92": [] } }

Probably, I will look into the Project.json stuff next, which I did not play with before. Thank you very much so far,

MFG

AArnott commented 8 years ago

The auto restore on build should be disabled or else VS build will break what build.ps1 -restore does. Also, your project.lock.json file should be much larger than that.

HeikoStudt commented 8 years ago

As I see it now, it is much larger after build.cmd -restore. :-) Yes, you are right. It was VS restore.

If you are so kind to add those two facts into contribution.md? a) Switch off Visual Studio/Nuget Package Manager/General/Automatically check for missing packages during build b) Call the command from "Developer Command Line": "build.cmd -restore" or the powershell equivalent

Thanks a lot,

MFG

PS: If I find some time, I try to add some APIs I probably will use in my current pet project. Is there any license concern to copy over pinvoke.net APIs/Docs after having tested them?

AArnott commented 8 years ago

Good suggestion. I've added a section to contrib

HeikoStudt commented 8 years ago

Thank you very much. Now the issue is really closed. :-)

MFG

AArnott commented 8 years ago

Regarding your pinvoke.net licensing question, I know it has come up before and I had done some research on it. I just forgot the result. Does anyone else know? Otherwise I can dig it back up.

AArnott commented 8 years ago

It looks like anything on pinvoke.net is fair game to use in this project, per its license.

AArnott commented 8 years ago

I've added a note about the pinvoke.net license to our contrib doc