daveaglick / Scripty

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

MS Build compiling csx before PreBuildEvent #109

Open JCKodel opened 7 years ago

JCKodel commented 7 years ago

I'm forced to use MSBuild stuff because CustomTool is not supported by Scripty in a .net standard project. To use an assembly in my .csx script, I have first to copy it to the same folder as the .csx file (I'm using a PreBuild Event to do this, because .csx is in project B and the assembly I want is in project A).

The issue is: the Scripty MSBuild stuff is running before the PreBuildEvent, so, in the first time, there is no DLL copied and the .csx gives me such error. Then, when the dll is copied, it is always the not-the-latest version (because Scripty uses whatever there is in the disk and then AFTER, the PreBuildEvent is executed, thus copying the new version).

This is my .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
  </PropertyGroup>
</Project>

This project (let's call it ProjectSample) references another .net standard 1.4 project (called Nexus). The .csx will also use the project Nexus (it is a XML deserializer).

It is expected that Scripty runs only AFTER PreBuildEvent occurs.

Echo-8-ERA commented 7 years ago

Couldn't you just add a target that runs before Scripty does its thing? e.g.:

<Target Name="CopyMyDLL" BeforeTargets="EvaluateScriptyFiles">
  <!-- Insert stuff to do the copying -->
</Target>
JCKodel commented 7 years ago

@Echo-8-ERA: There are no <Target> in .net standard, apparently =\ Don't know how this new .csproj works =\

Echo-8-ERA commented 7 years ago

Yes there is...

Create a project file with this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <Target Name="HelloWorldTarget" BeforeTargets="BeforeBuild">
    <Message Text="Hello World!"/>
  </Target>
</Project>

Now run dotnet build /verbosity:normal and read the output