Scripty
Scripty copied to clipboard
Adds checks to make sure output isn't added by both MsBuild task and VS extension
Hi,
I have a warning about a .cs file that is included twice in the project when compiling and I think it is related to the ScriptyGenerator custom tool. Here are the steps to reproduce the issue:
- created a new project and reference the Scripty.MsBuild Nuget package (I could not find a Nuget package for Scripty.CustomTool)
- add a file called
mapper.csx
and add this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Evaluation;
string propertyName = "Bar";
Output.WriteLine($@"
public class Foo
{{
public int {propertyName} => 42;
}}");
- change the custom tool of the file to use the ScriptyGenerator
- build the project
There is a warning available in the Error list
window. Is this fixable?
Thanks
A couple things are probably going on here. The CustomTool is installed as a Visual Studio extension from the Visual Studio Gallery, and once installed, is available for every project on that system. The MSBuild task on the other hand is installed via NuGet on a per-project basis.
It sounds like you have both installed in this project, and so they're both handling the script and generating the output file (the custom tool is run at "design time" while the MSBuild task is run at build time). The custom tool is running the script and adding the output to the project and then the MSBuild task is running it again, also adding it to the project (hence the warning).
The fix for now would be to either remove the CustomTool property from the script and rely on the MSBuild task at build time to evaluate it, or remove the Scripty.MSBuild NuGet package and rely on the custom tool to evaluate the script.
Long-term, I should probably add some smarts to both the MSBuild task and the custom tool to avoid re-adding the same output file(s) if the script was already evaluated by the other tool.
I will remove the CustomTool.
Thanks
No problem. I'd actually like to leave this open to track adding additional checks to the tools.