daveaglick / Scripty

Tools to let you use Roslyn-powered C# scripts for code generation
MIT License
621 stars 69 forks source link

Extension fails to work in 15.8 Preview 3 #127

Open CoolDadTx opened 6 years ago

CoolDadTx commented 6 years ago

Taking a simple script and trying to run the custom tool via the extension in 15.8 Preview 3 fails. The error is: System.TypeLoadException: Could not load type 'Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace' from assembly 'Microsoft.CodeAnalysis.Workspaces.Desktop, Version=2.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. at Scripty.Core.ScriptEngine.d__6.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine) at Scripty.Core.ScriptEngine.Evaluate(ScriptSource source) at Scripty.ScriptyGenerator.GenerateCode(String inputFileContent) in E:\Code\Scripty\src\Scripty.CustomTool\ScriptyGenerator.cs:line 58

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class AppSettings
{
}
daveaglick commented 6 years ago

I'm not totally surprised. Scripty is a little behind the times right now. I've been working a ton over in https://github.com/daveaglick/Buildalyzer to make sure I can build any type of project from any type of host. That project serves as a foundation for Scripty and is important because being able to build the host project so that we can introspect it is the fundamental goal of Scripty. Once that project is stable enough, I'm going to circle back to Scripty and update it for the most recent versions of MSBuild and Roslyn.

MelGrubb commented 6 years ago

The Visual Studio extenstion seems to be entirely missing at this point. Is this related? I just ran into a limitation with a set of T4 templates that I've used for years, and was looking for some way to keep them alive in the .Net Core space. That doesn't look possible, so I thought I'd rewrite them in Scripty. I'm not getting anything though. No output or complaints from the MSBuild NuGet package. Nothing. I'd like to try the extension, but it's seemingly AWOL at the moment.

daveaglick commented 6 years ago

Sorry about that. I removed it for now. Scripty is in need of an update (which I fully intend to do sometime this year), but in the meantime there were reports of the vsix breaking Visual Studio. Since I don't have time to look closer at it right now, I unlisted the package lest it get swamped with bad reviews. The MSBuild package should still work though, and you could build the vsix from source and locally install it if you really need to.

If you're not seeing anything from the build output and Scripty isn't generating files, perhaps you're in a newer scenario I haven't tested yet. Are you using a SDK-style project or is it .NET Core? Those will be supported in the future, but I honestly don't know how well they'll work right now.

Keep an eye out for a new Scripty rewrite, probably sometime in the last couple months of the year.

MelGrubb commented 6 years ago

It’s a .Net Core application, specifically a REST API. If there’s a known problem there, then I don’t know what I’m going to do. Hand-typing this stuff is not really an option.

Back story: I use T4 templates to build the repetitive parts of “Builder” objects used to generate test objects for the unit and integration tests. It’s worked well for me over the years, and I’ve got it down to where I like the output. I just wouldn’t want to have to type it all by hand. The end result is something like this:

            var testUser = UserBuilder.Typical().WithFirstName(“Bob”).Object();

The .Object() on the end kicks off the actual building of the object, and is shamelessly mirroring the naming of Moq. It’s the “WithFirstName” part that gets auto-generated, one method for each property. The “Typical” is more hand-crafted, and creates a randomly-generated User object with all of the “typical” properties filled in. “Typical” is up to the developers, but the end result is that we agree on what a typical user looks like, and build up the generator to return that. If a new property gets added later on, and we think a typical user would have that, then we add it to the builder and hopefully all of the tests remain happy. It’s like personas for test objects. In this case, if it was important to a particular unit test that the user be named “Bob”, they would override that property before generating the object.

In the end, test contexts are much easier to set up, but there is a LOT of repetitive code that goes into making the syntax work, and that’s where I need the code generation.


From: Dave Glick notifications@github.com Sent: Wednesday, July 25, 2018 12:09:31 PM To: daveaglick/Scripty Cc: Mel Grubb; Comment Subject: Re: [daveaglick/Scripty] Extension fails to work in 15.8 Preview 3 (#127)

Sorry about that. I removed it for now. Scripty is in need of an update (which I fully intend to do sometime this year), but in the meantime there were reports of the vsix breaking Visual Studio. Since I don't have time to look closer at it right now, I unlisted the package lest it get swamped with bad reviews. The MSBuild package should still work though, and you could build the vsix from source and locally install it if you really need to.

If you're not seeing anything from the build output and Scripty isn't generating files, perhaps you're in a newer scenario I haven't tested yet. Are you using a SDK-style project or is it .NET Core? Those will be supported in the future, but I honestly don't know how well they'll work right now.

Keep an eye out for a new Scripty rewrite, probably sometime in the last couple months of the year.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdaveaglick%2FScripty%2Fissues%2F127%23issuecomment-407809392&data=02%7C01%7C%7C893bd7c14acc426020bf08d5f2490189%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636681317719946849&sdata=1IgPHjDr5o3T3sO9hy%2BsSjGhvIkpvf7hDiuKVZU7cX8%3D&reserved=0, or mute the threadhttps://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABGZB5_xP-F6X0pVbZAoCWXoRMN6K97Hks5uKJg7gaJpZM4U9ZEX&data=02%7C01%7C%7C893bd7c14acc426020bf08d5f2490189%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636681317719946849&sdata=dTH1%2FvEQsyhBg0tYRetK65JWfg2c3KKra8KLA2ugYvk%3D&reserved=0.

dude0001 commented 6 years ago

Can you put the extension back up on the marketplace, or can you provide an alternate link to download the extension? Removing the extension has essentially crippled anyone still using this in VS versions prior to 15.8. We are still using this on production environments and we need to be able to set this up on new development machines using an older VS version for those that have updated to 15.8. I'm scrambling today to try to find a machine that hasn't been updated to VS 15.8 and has the extension installed.

Regarding the actual issue, it looks like MS actually broken multiple packages that use MSBuildWorkspace and they have fixed the issue. It looks simple as just updating this new version https://github.com/dotnet/roslyn/issues/29334

daveaglick commented 6 years ago

@dude0001

Removing the extension has essentially crippled anyone still using this in VS versions prior to 15.8

Definitely don't want to cause problems for existing Scripty users. I know it's been a long time since an update, but I'm still planning on updating and rewriting Scripty for a 1.0 release soonish (I swear!) Some of the pieces like Buildalyzer are finally falling into place.

Can you put the extension back up on the marketplace, or can you provide an alternate link to download the extension?

I'm very hesitant to add it back to the gallery since there's been reports of breaks and I can't guarantee it'll work on newer versions of Visual Studio at this point. However, I've added the VSIX to the 0.7.4 release here on GitHub so anyone who needs/wants it can download it until the next release gets added back to the gallery.

Regarding the actual issue, it looks like MS actually broken multiple packages that use MSBuildWorkspace and they have fixed the issue.

At this point, MSBuildWorkspace is a non-started for Scripty use. It was totally broken for a long time (hence my break here to focus on Buildalyzer), and still remains broken for all but the most simple scenarios. For example, it doesn't work at all under a .NET Core host. Buildalyzer resolves some of these issues (though it's not perfect), so the next version of Scripty will use it and a Roslyn AdhocWorkspace instead of MSBuildWorkspace.

dude0001 commented 6 years ago

Thank you for the link to the VSIX, didn't think to look there. I think that will help us work around this for now but very much looking forward to a fix so we can continue to use Scripty.

alphaleonis commented 6 years ago

I encountered the same error on one of my own extensions. Apparently there doesn't seem to be a good way to make an extension that is compatible with both 15.8 and earlier versions. See https://github.com/dotnet/roslyn/issues/29334 for more info.

(As a summary, they moved the MSBuildWorkspace into a new assembly without type forwarding, which requires us to reference the 2.9.0 version of Microsoft.CodeAnalysis assemblies to use it on VS 15.8)

InvalidCast44 commented 6 years ago

any news please?

daveaglick commented 6 years ago

@InvalidCast44 Nope.

My thinking is still about the same as it was - I'm still planning on circling back to Scripty at some point, though I don't have an estimate on when or how soon that'll be ("soonish" may have been a bit optimistic). I have other higher-priority OSS work at the moment that'll keep me busy into the immediate future.

InvalidCast44 commented 6 years ago

i quickly tried to recompile your code, adding the new missing package "microsoft.codeanalysis.workspaces.msbuild" but i get this error in Scripty.CustomTool:

CreatePkgDef : error : ProvideBindingRedirectionAttribute: Invalid value specified for NewVersion.

i would like to have a "crappy" version of my own on my machine, but this block me. any ideas?

InvalidCast44 commented 6 years ago

i finally managed to get your extension work with vs 15.8.9 :-) i had problems with vsix: i couldn't register custom tool i created another vsix:

and this time it worked.

so basically, adding "microsoft.codeanalysis.workspaces.msbuild" package is all you need to make scripty work again. for the moment i will use my crappy extension, it does the job (thanks to your code obviously :-) )

KCarterSr commented 5 years ago

InvalidCast44 , can I get a copy of your vsix?

Thanks

KCarterSr commented 5 years ago

Anybody know how to get in touch with InvalidCast44. I need this baaad.

InvalidCast44 commented 5 years ago

if it's ok with daveaglick i can post a link to download modified sources + compiled vsix

daveaglick commented 5 years ago

Fine with me - I really appreciate you filling in the gap until I’ve got time to revisit.

InvalidCast44 commented 5 years ago

it's a little thing compared to what you've done for us ;-) please remind that it's a quick fix, it was not intented to be released to anyone but me http://dl.free.fr/b7ElBRNUC contains modified git clone + compiled vsix AFAIR i change some description string to be sure my version was the one that was registered. but anyway, the most important is that custom tool "ScriptyGenerator" is still registered

KCarterSr commented 5 years ago

Man, thanks so much. Im fed up with tools for T4. All the good tools except for ForTea have gone bust. And ForTea takes soooo long for updates to come out each time Resharper is updated, I end up waiting for sometimes months before I can continue using it for my code.

K. L. Carter Sr.

bradtwurst commented 4 years ago

We've used scripty in the past to generate code and it's been a very useful tool.

Since visual studio has been updated, the extension was no longer working.

Calling the scripty.exe worked but, to simplify calling the .exe, we would end up regenerating all the .csx output on each change that we wanted to capture.

I've created a fork of scripty with a 'vs2019' branch in which I've gone through and 'updated' the code to work in our situation (vs2019 - framework - not core at this time)

It appears to be working (on my machine), but I don't know if it is worth a pull request as it could not work on older visual studios with the changes I've done.

Thoughts?