AArnott / CodeGeneration.Roslyn

Assists in performing Roslyn-based code generation during a build.
Microsoft Public License
408 stars 59 forks source link

Assembly attributes support #67

Closed Pzixel closed 6 years ago

Pzixel commented 6 years ago

This is an attempt to provide generation for a global attribute which have no type to sit on.

It also adds ProjectDirectory attribute because if attributes have no type to interact it should still have some way to get information about project. This guy should fix #66 because with knowlenge of project directory I can recursively get all needed files and transform them as I need. Test example just creates a const public field with path to the csproj, however, actual code generator may use it to list all .myextension files and use them to create an output.

Pzixel commented 6 years ago

What's about mergin this guy? I don't really like to create my own nuget source just to use this code. I have to write a generator that uses this feature today..

amis92 commented 6 years ago

Well, we'll have to wait for @AArnott here :) I think you'll have to setup custom nuget if you need it today, especially since releases here are scarce lately ;)

Pzixel commented 6 years ago

@amis92 okay. Can you elaborate then, please?

I have built all packages into my private nuget (and have set version to 1.5 to pretend it's release), however I can't get it compiled - dotnet exited with code 1. Can you elaborate, please?

Here is my repo: https://github.com/Pzixel/Solidity.Roslyn .

I have built it with current branch and following version.json:

{
  "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
  "version": "1.5",
  "publicReleaseRefSpec": [
    "^.+$",
  ],
  "cloudBuild": {
    "buildNumber": {
      "enabled": true
    }
  }
}

I have no idea what could be wrong...

Output:

...
-r
C:\Users\Alex\.nuget\packages\xunit.assert\2.3.1\lib\netstandard1.1\xunit.assert.dll
-r
C:\Users\Alex\.nuget\packages\xunit.extensibility.core\2.3.1\lib\netstandard1.1\xunit.core.dll
-r
C:\Users\Alex\.nuget\packages\xunit.extensibility.execution\2.3.1\lib\netstandard1.1\xunit.execution.dotnet.dll
--out
obj\Debug\netcoreapp2.0\
--projectDir
C:\Users\Alex\Documents\Repo\Solidity.Roslyn\Solidity.Roslyn.Test
--generatedFilesList
obj\Debug\netcoreapp2.0\4fp51aq5.wrr
--
ContractTest.cs
Version for package `dotnet-codegen` could not be resolved.
C:\Users\Alex\.nuget\packages\codegeneration.roslyn.buildtime\1.5.0\build\CodeGeneration.Roslyn.BuildTime.targets(20,5): error MSB6006: "dotnet" exited with code 1.

And

1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(4968,5): error MSB3541: Files has invalid value "C:\Users\Alex\Documents\Repo\Solidity.Roslyn\Solidity.Roslyn\bin\Debug\netstandard2.0\Solidity.Roslyn.deps.json C:\Users\Alex\Documents\Repo\Solidity.Roslyn\Solidity.Roslyn\bin\Debug\netstandard2.0\Solidity.Roslyn.dll C:\Users\Alex\Documents\Repo\Solidity.Roslyn\Solidity.Roslyn\obj\Debug\netstandard2.0\Solidity.Roslyn.csprojResolveAssemblyReference.cache C:\Users\Alex\Documents\Repo\Solidity.Roslyn\Solidity.Roslyn\obj\Debug\netstandard2.0\Solidity.Roslyn.csproj.CoreCompileInputs.cache C:\Users\Alex\Documents\Repo\Solidity.Roslyn\Solidity.Roslyn\obj\Debug\netstandard2.0\Solidity.Roslyn.AssemblyInfoInputs.cache C:\Users\Alex\Documents\Repo\Solidity.Roslyn\Solidity.Roslyn\obj\Debug\netstandard2.0\Solidity.Roslyn.AssemblyInfo.cs". The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

I wasted several hours by trying to make it work and hitting wall by my head. Both csproj don't compile for no reason. I'm just out of ideas and hope except take nuget when it gets merged.

amis92 commented 6 years ago

Please take a look here: https://github.com/AArnott/CodeGeneration.Roslyn/issues/54#issuecomment-350784608

The error is quite cryptic, and my best guess is because you do not reference DotNetCliTool in csproj. Of course the version would be what you set, 1.5. That's all I can think of.

Pzixel commented 6 years ago

@amis92 you can see the csproj and see that I atually do reference it: https://github.com/Pzixel/Solidity.Roslyn/blob/master/Solidity.Roslyn.Test/Solidity.Roslyn.Test.csproj#L15-L18

And as I said, it happens even if you just build an attribute itself (without trying to apply it somewhere).

Can you clone and test it on your PC, please?

amis92 commented 6 years ago

I will be home soon, but from my experience it doesn't work well in xunit tests (at all). You'd have to have generated code in separate assembly referenced from test.

Pzixel commented 6 years ago

@amis92 you didn't get it. It doesn't compile even if I exclude test project at all :) Maybe I'm just doing it wrong.

amis92 commented 6 years ago

I can't try out your repository, because I don't have access to your private nuget feed, so it won't build for me.

Pzixel commented 6 years ago

@amis92 you don't need my nuget, you can build your own, it's just as simple as build this branch. Build them and use debug/PublishOutput as local nuget source.

I can share nugpkg, if needed.

Pzixel commented 6 years ago

Hi there! Any progress? I can provide prevompiled packages, if you have no possibility to pack them: https://1drv.ms/u/s!Aho9_FLDH6NYg_wGpY3HjHyTQBK55g

Pzixel commented 6 years ago

Hey everybody? Why it's so silent here?

@amis92 btw, you requested changes that I have already done. What's about marking it as fixed?

Pzixel commented 6 years ago

@AArnott Could you publish a new nuget version please? I thought it's configured to be automatically build by appveyor but it isn't.

AArnott commented 6 years ago

It is published automatically, to an AppVeyor feed. Publishing to nuget.org is a separate step. Yes, I can get that done today.

AArnott commented 6 years ago

v0.4.37 is now on nuget.org

Pzixel commented 6 years ago

@AArnott hello again.

For some reason, I'm not able to get this version. It fails with

Restoring packages for C:\Users\Alex\Source\Repos\RemoteClient.Roslyn\RemoteClient.Roslyn\RemoteClient.Roslyn.csproj... GET https://api.nuget.org/v3-flatcontainer/codegeneration.roslyn.attributes/index.json GET https://dotnetmyget.blob.core.windows.net/artifacts/dotnet-corefxlab/nuget/v3/flatcontainer/codegeneration.roslyn.attributes/index.json OK https://api.nuget.org/v3-flatcontainer/codegeneration.roslyn.attributes/index.json 691ms NotFound https://dotnetmyget.blob.core.windows.net/artifacts/dotnet-corefxlab/nuget/v3/flatcontainer/codegeneration.roslyn.attributes/index.json 846ms NU1102: Unable to find package CodeGeneration.Roslyn.Attributes with version (>= 1.0.0)

  • Found 9 version(s) in api.nuget.org [ Nearest version: 0.4.37 ]
  • Found 0 version(s) in Microsoft Visual Studio Offline Packages
  • Found 0 version(s) in corefxlab

Package restore failed. Rolling back package changes for 'RemoteClient.Roslyn'. Time Elapsed: 00:00:00.9908081 ========== Finished ==========

I'm not sure why it asks for 1.0.0, I didn't change anything related to versions in this PR. Can you elaborate, please?

But I can restore 0.4.11... That's weird.

amis92 commented 6 years ago

@Pzixel I've raised #68 for this.