Code Monkey home page Code Monkey logo

Comments (10)

NeVeSpl avatar NeVeSpl commented on July 23, 2024

#84 is not similar unfortunately. VS addin and source generator are using exactly the same runtime/code for compiling .nt.cs files. Theoretically the set of available assemblies should be the same, but environments are completely different VS is still on .net4.8, Rider probably on net.core. Your first thought was good, somehow source generator run by Rider is trying to do compilation targeting net.core, but all referenced assemblies are provided for net.standard, and I do not see any line that would tell compiler to explicitly target net.standard:

private static CSharpCompilation PrepareCompilation(IEnumerable<SyntaxTree> syntaxTreesToCompile, string configurationName)
{
var refTypes = new[] {
typeof(object),
typeof(Enumerable),
typeof(IEditorConfig),
typeof(ICodeModel),
typeof(ActionFunctions),
typeof(ISet<>),
typeof(System.Text.Json.JsonSerializer),
typeof(System.Text.RegularExpressions.Regex)
};
var references = refTypes.Select(x => MetadataReference.CreateFromFile(x.Assembly.Location)).ToList();
var netstandardAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "netstandard");
var netstandardAssembly = netstandardAssemblies.OrderByDescending(x => x.GetName().Version).FirstOrDefault();
references.Add(MetadataReference.CreateFromFile(netstandardAssembly.Location));
var runtimeDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
var runtimeDllPath = Path.Combine(runtimeDir, "System.Runtime.dll");
references.Add(MetadataReference.CreateFromFile(runtimeDllPath));
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithOptimizationLevel(OptimizationLevel.Debug);
var compilation = CSharpCompilation.Create($"NTDynamic{configurationName}Assembly", syntaxTrees: syntaxTreesToCompile, references: references, compilationOptions);
return compilation;
}

from ntypewriter.

Auirsblade avatar Auirsblade commented on July 23, 2024

Yea that certainly makes sense, Rider does seem to be trying to compile using Core even though when peeking at the assembly explorer it recognizes the NTypewriter.SourceGenerator assembly as .NET Standard v2... To confirm your theory I uninstalled the extension from VS and it still compiled just fine, so it's just a Rider issue.

from ntypewriter.

NeVeSpl avatar NeVeSpl commented on July 23, 2024

The problem may be in how assemblies are resolved for the compilation, in one of the future releases I will try to replace manually setting references to assemblies with this library:

https://github.com/jaredpar/basic-reference-assemblies

It looks promising, it should give more deterministic results, and hopefully the same results for VS/48 vs Rider/.core, but I wonder if it will work with Blazor .... but that is different story.

from ntypewriter.

Auirsblade avatar Auirsblade commented on July 23, 2024

Another interesting tidbit - I ran the source generator code through CI, and jenkins also failed to build it. Seeing that, I figured I'd try running it through VS via the terminal dotnet build command and it also failed, so there must be something very specific about what VS does when it builds that's different than the usual dotnet build?

Update: I then ran MSBuild from rider and it works. So it seems to be an MSBuild vs dotnet build issue.

It seems the issue is indeed core/framework. dotnet build is using this and fails (both locally and via CI):
MSBuild version 17.8.3+195e7f5a3 for .NET
while MSBuild uses this and works (in VS and Rider):
MSBuild version 17.8.5+b5265ef37 for .NET Framework

from ntypewriter.

NeVeSpl avatar NeVeSpl commented on July 23, 2024

Problem is fixed in NTypewriter.SourceGenerator v0.3.2

from ntypewriter.

Auirsblade avatar Auirsblade commented on July 23, 2024

Sweet I'll get it tested once the CI finishes. Cheers!

from ntypewriter.

Auirsblade avatar Auirsblade commented on July 23, 2024

Updated to the latest nuget packages for .Runtime and .SourceGenerator and still having compiling issues with MSBuild version 17.8.3+195e7f5a3 for .NET, I'll poke around and run the source code locally and see if I can get something working.

from ntypewriter.

NeVeSpl avatar NeVeSpl commented on July 23, 2024

That is impossible :D. The same error message? Did you delete obj and bin folders to make sure that something is not cached?
I was able to reproduce problem, and indeed there was difference between MSbuild for .NET vs .NET Framework, but using basic-reference-assemblies seems to resolved problem.

from ntypewriter.

Auirsblade avatar Auirsblade commented on July 23, 2024

I ran a clean, but didn't manually delete bin and obj, I can try that too :)

from ntypewriter.

Auirsblade avatar Auirsblade commented on July 23, 2024

I ran a clean, but didn't manually delete bin and obj, I can try that too :)

Yep same result after bin/obj delete and rebuild

from ntypewriter.

Related Issues (20)

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.