Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Trouble with referenced third-party libraries #130

Open
MelGrubb opened this issue Aug 22, 2018 · 2 comments
Open

Trouble with referenced third-party libraries #130

MelGrubb opened this issue Aug 22, 2018 · 2 comments

Comments

@MelGrubb
Copy link

MelGrubb commented Aug 22, 2018

I have a T4 script which I've converted to Scripty so that it can run as part of an AspNetCore solution. The script builds test object factories by reflecting over my Data assembly, where the EF models are defined. The main API project uses AspNet Identity, and so my User object inherits from Microsoft.AspNetCore.Identity.IdentityUser, and this is causing a problem for my script when the reflection tries to build the property type name like this.

var propertyTypeName = property.PropertyType.ToString().Replace("``1[", "<").Replace(']', '>');

The error that I'm getting when the script executes is

// An error occurred while generating property CreatedBy: Could not load file or assembly 'Microsoft.Extensions.Identity.Stores, Version=2.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.

If I break the inheritance from IdentityUser, this code runs just fine, but it seems that the code can't reflect over the ...Identity.Stores assembly because it's not in the bin folder when the script is running. I've added the appropriate NuGet packages to the unit test project hoping that it would copy them in, but it doesn't seem to be doing that.

What do I need to do to make the external assemblies visible to Scripty? I can't be the only one who's run into this problem, can I?

@MelGrubb
Copy link
Author

It would appear that this might be an order of operations problem. I have added the following to the PropertyGroup element of my csproj file

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

However, at the time that the script is running, this copy will not have happened yet, so the dll is unavailable, and I get a different error. I've managed to work around the problem by adding this element to the Data layer project instead, and then adding the following to the top of the script.

#r "../Foo.Data/bin/Debug/netcoreapp2.1/Microsoft.Extensions.Identity.Stores.dll"

It's a nasty direct reference, but at least it's a relative path. This has solved the problem for me for now, but this issue might help someone else in the future. A better solution would be for the script to somehow resolve project references better on its own, but I'm up and running for now.

@daveaglick
Copy link
Owner

Glad you were able to get it working.

It's a nasty direct reference, but at least it's a relative path. This has solved the problem for me for now, but this issue might help someone else in the future. A better solution would be for the script to somehow resolve project references better on its own, but I'm up and running for now.

Yep, totally agree. Since Scripty is based on the Roslyn scripting engine the #r preprocessor directive is the correct answer right now.

My longer-term plan is to automatically add project references to the script host prior to evaluation. That's a little tricky because the only reliable way to get that is from MSBuild during the Scripty MSBuild task (and what to do when evaluating via the Visual Studio extension, for example?). In any case, this'll hopefully get a bit better in the future.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants