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

Scripty doesn't work in SDK-style projects #120

Open
thomaslevesque opened this issue Oct 27, 2017 · 6 comments
Open

Scripty doesn't work in SDK-style projects #120

thomaslevesque opened this issue Oct 27, 2017 · 6 comments

Comments

@thomaslevesque
Copy link

thomaslevesque commented Oct 27, 2017

When the project is in the new .NET Core csproj format ("SDK-style" project), the custom tool doesn't work. There's no error, but nothing is generated.

The Scripty.MSBuild package doesn't work either; the build fails with this error:

Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "C:\Users\ThomasLEVESQUE\.nuget\packages\scripty.msbuild\0.7.4\tools\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

Sample project that demonstrates both issues:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Scripty.MsBuild" Version="0.7.4" />
  </ItemGroup>

  <ItemGroup>
    <None Update="Foo.csx">
      <Generator>ScriptyGenerator</Generator>
    </None>
  </ItemGroup>

</Project>
@daveaglick
Copy link
Owner

I can confirm Scripty can work with SDK projects that target .NET Framework. Not sure about the custom tool, but I've gotten the MSBuild task up and running on several SDK projects. It's really strange that it's looking for an Sdk.props file - it's like your build is looking for the whole SDK under the Scripty library.

Perhaps there is a difference between building with dotnet build and MSBuild. I couldn't get the former to work due to assembly mismatches between the SDK MSBuild task libraries and the ones Scripty references, but MSBuild worked fine:

2017-10-27_10h52_52

Work on these types of issues is ongoing (though it may not seem like it from the commits). Scripty will be undergoing a major overhaul to target .NET Standard soon. Right now the work is happening in the Buildalyzer repo. That will give Scripty a new foundation for compiling any project type on any platform and it's almost done. Then Scripty will be rewritten to use Buildalyzer and go all-in on the new stuff. It's taking a little bit of time to work everything out - there are so many hidden pitfalls, especially since build tools like Scripty are kind of pushing the envelope. Hang tight.

@thomaslevesque
Copy link
Author

Thanks for your answer.

I can confirm Scripty can work with SDK projects that target .NET Framework. Not sure about the custom tool, but I've gotten the MSBuild task up and running on several SDK projects. It's really strange that it's looking for an Sdk.props file - it's like your build is looking for the whole SDK under the Scripty library.

I just noticed something strange: it doesn't build in Visual Studio, but it works when I invoke MSBuild from the command line... Not sure what's going on.

@Sebazzz
Copy link

Sebazzz commented Nov 18, 2017

It is even weirder. I got it to work initially in Visual Studio, but my third build failed with the message above.

@StingyJack
Copy link
Contributor

Its not specific to scripty i dont think...

dotnet/project-system#2687

@lordmilko
Copy link

lordmilko commented Jul 7, 2019

Scripty appears to work fine when compiling .NET Core projects in Visual Studio, however as alluded to by @daveaglick when compiling with dotnet.exe it explodes trying to load .NET Framework specific assemblies such as Microsoft.Build.Utilities.v4.0.dll (which is located under C:\Windows\Microsoft.NET\[Framework | Framework64] rather than your .NET Core SDK install path).

Since all Scripty.MsBuild.dll does is invoke the Scripty.exe application with the required build arguments, you can work around this issue by disabling the default Scripty.MsBuild.targets file and then emulating the functionality it provides inside of your project (such as by writing your own Scripty.MsBuild.targets file)

Scripty.MsBuild.Targets

<Project>
  <PropertyGroup>
    <ScriptyVersion>0.7.4</ScriptyVersion>
    <ScriptyExe>$(NuGetPackageRoot)scripty.msbuild\$(ScriptyVersion)\tools\Scripty.exe</ScriptyExe>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Scripty.MsBuild" Version="$(ScriptyVersion)" PrivateAssets="all">
      <ExcludeAssets>build</ExcludeAssets>
    </PackageReference>
  </ItemGroup>

  <Target Name="EvaluateScriptyFiles" BeforeTargets="DispatchToInnerBuilds">
    <Exec Command="&quot;$(ScriptyExe)&quot; &quot;$(MSBuildProjectFullPath)&quot; @(ScriptyFiles->'&quot;%(Identity)&quot;', ' ') -p Configuration=$(Configuration)" StandardOutputImportance="low" />
  </Target>
</Project>

Project.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <Import Project="Scripty.MsBuild.targets" />

  <ItemGroup>
    <ScriptyFiles Include="File.csx" />
    <Compile Include="File.cs" Visible="false" />
  </ItemGroup>
</Project>

This configuration also prevents Scripty from tripping over itself when building multiple target frameworks (as a result of being evaluated before DispatchToInnerBuilds rather than BeforeBuild which Scripty normally uses)

@CZEMacLeod
Copy link

Just a quick note to tidy up using GeneratePathProperty

Scripty.MsBuild.Targets

<Project>
  <ItemGroup>
    <PackageReference Include="Scripty.MSBuild" Version="0.7.4">
      <PrivateAssets>all</PrivateAssets>
      <ExcludeAssets>build</ExcludeAssets>
      <GeneratePathProperty>true</GeneratePathProperty>
    </PackageReference>
  </ItemGroup>

  <Target Name="EvaluateScriptyFiles" BeforeTargets="DispatchToInnerBuilds">
    <PropertyGroup>
      <ScriptyExe>$(PkgScripty_MsBuild)\tools\Scripty.exe</ScriptyExe>
    </PropertyGroup>
    <Exec Command="&quot;$(ScriptyExe)&quot; &quot;$(MSBuildProjectFullPath)&quot; @(ScriptyFiles->'&quot;%(Identity)&quot;', ' ') -p Configuration=$(Configuration)" StandardOutputImportance="low" />
  </Target>
</Project>

# 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

6 participants