diff --git a/Dotnet.Script.sln b/Dotnet.Script.sln index 43cd597b..ea675183 100644 --- a/Dotnet.Script.sln +++ b/Dotnet.Script.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27004.2005 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31129.286 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dotnet.Script", "src\Dotnet.Script\Dotnet.Script.csproj", "{057F56AD-AF29-4ABD-B6DE-26E4DEE169F7}" EndProject @@ -14,9 +14,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dotnet.Script.DependencyMod EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dotnet.Script.DependencyModel.NuGet", "src\Dotnet.Script.DependencyModel.Nuget\Dotnet.Script.DependencyModel.NuGet.csproj", "{E361528F-178A-4489-AF01-FFD3A7122D99}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dotnet.Script.Desktop.Tests", "src\Dotnet.Script.Desktop.Tests\Dotnet.Script.Desktop.Tests.csproj", "{B0E5959C-6E7F-4023-96BA-5AD4A5E00541}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dotnet.Script.Desktop.Tests", "src\Dotnet.Script.Desktop.Tests\Dotnet.Script.Desktop.Tests.csproj", "{B0E5959C-6E7F-4023-96BA-5AD4A5E00541}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dotnet.Script.Shared.Tests", "src\Dotnet.Script.Shared.Tests\Dotnet.Script.Shared.Tests.csproj", "{8FFA2816-411E-437C-AB75-FFA546780E7A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dotnet.Script.Shared.Tests", "src\Dotnet.Script.Shared.Tests\Dotnet.Script.Shared.Tests.csproj", "{8FFA2816-411E-437C-AB75-FFA546780E7A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F20002BB-970C-4318-B618-58D478CAC405}" EndProject diff --git a/omnisharp.json b/omnisharp.json new file mode 100644 index 00000000..93c5d8d9 --- /dev/null +++ b/omnisharp.json @@ -0,0 +1,22 @@ +{ + "fileOptions": { + "systemExcludeSearchPatterns": [ + "**/TestFixtures/**/*.csx", + "**/ScriptPackages/**/*.csx" + ], + "userExcludeSearchPatterns": [] + }, + "script": { + "enableScriptNuGetReferences": true, + "defaultTargetFramework": "net5.0" + }, + "FormattingOptions": { + "organizeImports": true, + "enableEditorConfigSupport": true + }, + "RoslynExtensionsOptions": { + "enableImportCompletion": true, + "enableAnalyzersSupport": true, + "enableDecompilationSupport": true + } +} diff --git a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs index 6bf3809c..470a4e52 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs @@ -45,7 +45,7 @@ private async Task DownloadAndRunCode(ExecuteScriptCommandOpti private string GetLibrary(ExecuteScriptCommandOptions executeOptions) { - var projectFolder = FileUtils.GetPathToScriptTempFolder(Path.GetDirectoryName(executeOptions.File.Path)); + var projectFolder = FileUtils.GetPathToScriptTempFolder(executeOptions.File.Path); var executionCacheFolder = Path.Combine(projectFolder, "execution-cache"); var pathToLibrary = Path.Combine(executionCacheFolder, "script.dll"); diff --git a/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj b/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj index 2fbca8d9..24a97b2f 100644 --- a/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj +++ b/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj @@ -2,7 +2,7 @@ A cross platform library allowing you to run C# (CSX) scripts with support for debugging and inline NuGet packages. Based on Roslyn. - 1.0.1 + 1.1.0 filipw netstandard2.0 Dotnet.Script.Core @@ -16,12 +16,14 @@ false false false + true + ../dotnet-script.snk - + @@ -30,8 +32,9 @@ - - + + + diff --git a/src/Dotnet.Script.Core/Properties/AssemblyInfo.cs b/src/Dotnet.Script.Core/Properties/AssemblyInfo.cs index 103e9c2c..232e7d89 100644 --- a/src/Dotnet.Script.Core/Properties/AssemblyInfo.cs +++ b/src/Dotnet.Script.Core/Properties/AssemblyInfo.cs @@ -17,5 +17,5 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("684fefee-451b-4e68-b662-c16e3a7da794")] -[assembly: InternalsVisibleTo("Dotnet.Script.Shared.Tests")] -[assembly: InternalsVisibleTo("Dotnet.Script.Tests")] +[assembly: InternalsVisibleTo("Dotnet.Script.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f9790935628475aa44c2b2025427926d965f49fb36c645f5aeb7c03bd6183d31d02f42add3b2cb3ec4b0e508c5cf02478b41008ac8a6a6db314eaca3d678caac419d95e6e85e6cfb16fd93fec0bed8bc707875126e577ee7c96efe15737679d1a4dd1affec9e8f5c1b6f6518d51bcd1d3718b8b2694853eef059328ca81f6ea9")] +[assembly: InternalsVisibleTo("Dotnet.Script.Shared.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f9790935628475aa44c2b2025427926d965f49fb36c645f5aeb7c03bd6183d31d02f42add3b2cb3ec4b0e508c5cf02478b41008ac8a6a6db314eaca3d678caac419d95e6e85e6cfb16fd93fec0bed8bc707875126e577ee7c96efe15737679d1a4dd1affec9e8f5c1b6f6518d51bcd1d3718b8b2694853eef059328ca81f6ea9")] diff --git a/src/Dotnet.Script.Core/Scaffolder.cs b/src/Dotnet.Script.Core/Scaffolder.cs index 78cb9339..ef66970a 100644 --- a/src/Dotnet.Script.Core/Scaffolder.cs +++ b/src/Dotnet.Script.Core/Scaffolder.cs @@ -63,7 +63,7 @@ public void CreateNewScriptFile(string fileName, string currentDirectory) RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { // mark .csx file as executable, this activates the shebang to run dotnet-script as interpreter - _commandRunner.Execute($"/bin/chmod", $"+x {pathToScriptFile}"); + _commandRunner.Execute($"/bin/chmod", $"+x \"{pathToScriptFile}\""); } _scriptConsole.WriteSuccess($"...'{pathToScriptFile}' [Created]"); } diff --git a/src/Dotnet.Script.Core/ScriptPublisher.cs b/src/Dotnet.Script.Core/ScriptPublisher.cs index d1869e70..ed655fd8 100644 --- a/src/Dotnet.Script.Core/ScriptPublisher.cs +++ b/src/Dotnet.Script.Core/ScriptPublisher.cs @@ -1,10 +1,8 @@ -using Dotnet.Script.Core.Internal; using Dotnet.Script.DependencyModel.Environment; using Dotnet.Script.DependencyModel.Logging; using Dotnet.Script.DependencyModel.Process; using Dotnet.Script.DependencyModel.ProjectSystem; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Scripting; using System; using System.IO; using System.Reflection; @@ -13,7 +11,7 @@ namespace Dotnet.Script.Core { public class ScriptPublisher { - private const string ScriptingVersion = "3.8.0-5.final"; + private const string ScriptingVersion = "3.9.0"; private readonly ScriptProjectProvider _scriptProjectProvider; private readonly ScriptEmitter _scriptEmitter; diff --git a/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj b/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj index 3818c1d4..becaacfe 100644 --- a/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj +++ b/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj @@ -8,17 +8,19 @@ https://github.com/filipw/dotnet-script.git git script;csx;csharp;roslyn;nuget - 1.0.1 + 1.1.0 A MetadataReferenceResolver that allows inline nuget references to be specified in script(csx) files. dotnet-script dotnet-script latest + true + ../dotnet-script.snk - + diff --git a/src/Dotnet.Script.DependencyModel/AssemblyProperties.cs b/src/Dotnet.Script.DependencyModel/AssemblyProperties.cs index 50be859b..210cb3df 100644 --- a/src/Dotnet.Script.DependencyModel/AssemblyProperties.cs +++ b/src/Dotnet.Script.DependencyModel/AssemblyProperties.cs @@ -1,3 +1,3 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("Dotnet.Script.Tests")] \ No newline at end of file +[assembly: InternalsVisibleTo("Dotnet.Script.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f9790935628475aa44c2b2025427926d965f49fb36c645f5aeb7c03bd6183d31d02f42add3b2cb3ec4b0e508c5cf02478b41008ac8a6a6db314eaca3d678caac419d95e6e85e6cfb16fd93fec0bed8bc707875126e577ee7c96efe15737679d1a4dd1affec9e8f5c1b6f6518d51bcd1d3718b8b2694853eef059328ca81f6ea9")] \ No newline at end of file diff --git a/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs b/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs index 8acf2981..3c2f2970 100644 --- a/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs +++ b/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs @@ -44,10 +44,11 @@ public IEnumerable GetDependencies(string targetDirectory } // On .Net Core, we need to fetch the compilation references for framework assemblies separately. - if (defaultTargetFramework.StartsWith("netcoreapp3", StringComparison.InvariantCultureIgnoreCase)) + if (defaultTargetFramework.StartsWith("netcoreapp3", StringComparison.InvariantCultureIgnoreCase) || + defaultTargetFramework.StartsWith("net5", StringComparison.InvariantCultureIgnoreCase)) { var compilationreferences = _compilationReferenceReader.Read(projectFileInfo); - result.Add(new CompilationDependency("Microsoft.NETCore.App", "3.0", compilationreferences.Select(cr => cr.Path).ToArray(), Array.Empty())); + result.Add(new CompilationDependency("Dotnet.Script.Default.Dependencies", "99.0", compilationreferences.Select(cr => cr.Path).ToArray(), Array.Empty())); } return result; diff --git a/src/Dotnet.Script.DependencyModel/Compilation/CompilationReferencesReader.cs b/src/Dotnet.Script.DependencyModel/Compilation/CompilationReferencesReader.cs index 7a974e6b..4f0704ed 100644 --- a/src/Dotnet.Script.DependencyModel/Compilation/CompilationReferencesReader.cs +++ b/src/Dotnet.Script.DependencyModel/Compilation/CompilationReferencesReader.cs @@ -48,7 +48,7 @@ public IEnumerable Read(ProjectFileInfo projectFile) { File.Delete(referencePathsFile); } - var exitCode = _commandRunner.Execute("dotnet", $"build \"{pathToCompilationProjectFile}\" /p:OutputType=Library -o {outputDirectory}", workingDirectory); + var exitCode = _commandRunner.Execute("dotnet", $"build \"{pathToCompilationProjectFile}\" /p:OutputType=Library -o {outputDirectory} --nologo", workingDirectory); if (exitCode != 0) { throw new Exception($"Unable to read compilation dependencies for '{projectFile.Path}'. Make sure that all script files contains valid NuGet references"); diff --git a/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj b/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj index b3a3befb..c1141c7b 100644 --- a/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj +++ b/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj @@ -11,8 +11,10 @@ https://github.com/filipw/dotnet-script.git git script;csx;csharp;roslyn;omnisharp - 1.0.1 + 1.1.0 latest + true + ../dotnet-script.snk diff --git a/src/Dotnet.Script.Desktop.Tests/Dotnet.Script.Desktop.Tests.csproj b/src/Dotnet.Script.Desktop.Tests/Dotnet.Script.Desktop.Tests.csproj index fd6ac52f..cbe23b97 100644 --- a/src/Dotnet.Script.Desktop.Tests/Dotnet.Script.Desktop.Tests.csproj +++ b/src/Dotnet.Script.Desktop.Tests/Dotnet.Script.Desktop.Tests.csproj @@ -2,9 +2,11 @@ net472 + true + ../dotnet-script.snk - + all @@ -12,6 +14,7 @@ + diff --git a/src/Dotnet.Script.Extras/Dotnet.Script.Extras.csproj b/src/Dotnet.Script.Extras/Dotnet.Script.Extras.csproj index 84c07d06..5dadb071 100644 --- a/src/Dotnet.Script.Extras/Dotnet.Script.Extras.csproj +++ b/src/Dotnet.Script.Extras/Dotnet.Script.Extras.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Dotnet.Script.Shared.Tests/Dotnet.Script.Shared.Tests.csproj b/src/Dotnet.Script.Shared.Tests/Dotnet.Script.Shared.Tests.csproj index 0c609055..2b928e99 100644 --- a/src/Dotnet.Script.Shared.Tests/Dotnet.Script.Shared.Tests.csproj +++ b/src/Dotnet.Script.Shared.Tests/Dotnet.Script.Shared.Tests.csproj @@ -2,6 +2,8 @@ netstandard2.0 + true + ../dotnet-script.snk diff --git a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj index b08a3b76..504cb2c0 100644 --- a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj +++ b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj @@ -1,14 +1,16 @@ - net5.0 + net5.0;netcoreapp3.1;netcoreapp2.1 false + true + ../dotnet-script.snk runtime; build; native; contentfiles; analyzers all - + all diff --git a/src/Dotnet.Script.Tests/ExecutionCacheTests.cs b/src/Dotnet.Script.Tests/ExecutionCacheTests.cs index 64992f3c..7b4a0a15 100644 --- a/src/Dotnet.Script.Tests/ExecutionCacheTests.cs +++ b/src/Dotnet.Script.Tests/ExecutionCacheTests.cs @@ -1,5 +1,6 @@ -using System.IO; using Dotnet.Script.Shared.Tests; +using System; +using System.IO; using Xunit; using Xunit.Abstractions; @@ -25,10 +26,12 @@ public void ShouldNotUpdateHashWhenSourceIsNotChanged() WriteScript(pathToScript, "WriteLine(42);"); var firstResult = Execute(pathToScript); Assert.Contains("42", firstResult.output); + Assert.NotNull(firstResult.hash); WriteScript(pathToScript, "WriteLine(42);"); var secondResult = Execute(pathToScript); Assert.Contains("42", secondResult.output); + Assert.NotNull(secondResult.hash); Assert.Equal(firstResult.hash, secondResult.hash); } @@ -45,10 +48,12 @@ public void ShouldUpdateHashWhenSourceChanges() WriteScript(pathToScript, "WriteLine(42);"); var firstResult = Execute(pathToScript); Assert.Contains("42", firstResult.output); + Assert.NotNull(firstResult.hash); WriteScript(pathToScript, "WriteLine(84);"); var secondResult = Execute(pathToScript); Assert.Contains("84", secondResult.output); + Assert.NotNull(secondResult.hash); Assert.NotEqual(firstResult.hash, secondResult.hash); } @@ -85,6 +90,61 @@ public void ShouldCopyDllAndPdbToExecutionCacheFolder() } } + [Fact] + public void ShouldCacheScriptsFromSameFolderIndividually() + { + (string Output, bool Cached) Execute(string pathToScript) + { + var result = ScriptTestRunner.Default.Execute($"{pathToScript} --debug"); + return (Output: result.output, Cached: result.output.Contains("Using cached compilation")); + } + + using (var scriptFolder = new DisposableFolder()) + { + var pathToScriptA = Path.Combine(scriptFolder.Path, "script.csx"); + var pathToScriptB = Path.Combine(scriptFolder.Path, "script"); + + + var idScriptA = Guid.NewGuid().ToString(); + File.AppendAllText(pathToScriptA, $@"WriteLine(""{idScriptA}"");"); + + var idScriptB = Guid.NewGuid().ToString(); + File.AppendAllText(pathToScriptB, $@"WriteLine(""{idScriptB}"");"); + + + var firstResultOfScriptA = Execute(pathToScriptA); + Assert.Contains(idScriptA, firstResultOfScriptA.Output); + Assert.False(firstResultOfScriptA.Cached); + + var firstResultOfScriptB = Execute(pathToScriptB); + Assert.Contains(idScriptB, firstResultOfScriptB.Output); + Assert.False(firstResultOfScriptB.Cached); + + + var secondResultOfScriptA = Execute(pathToScriptA); + Assert.Contains(idScriptA, secondResultOfScriptA.Output); + Assert.True(secondResultOfScriptA.Cached); + + var secondResultOfScriptB = Execute(pathToScriptB); + Assert.Contains(idScriptB, secondResultOfScriptB.Output); + Assert.True(secondResultOfScriptB.Cached); + + + var idScriptB2 = Guid.NewGuid().ToString(); + File.AppendAllText(pathToScriptB, $@"WriteLine(""{idScriptB2}"");"); + + + var thirdResultOfScriptA = Execute(pathToScriptA); + Assert.Contains(idScriptA, thirdResultOfScriptA.Output); + Assert.True(thirdResultOfScriptA.Cached); + + var thirdResultOfScriptB = Execute(pathToScriptB); + Assert.Contains(idScriptB, thirdResultOfScriptB.Output); + Assert.Contains(idScriptB2, thirdResultOfScriptB.Output); + Assert.False(thirdResultOfScriptB.Cached); + } + } + private (string output, string hash) Execute(string pathToScript) { var result = ScriptTestRunner.Default.Execute(pathToScript); @@ -103,7 +163,7 @@ public void ShouldCopyDllAndPdbToExecutionCacheFolder() private static string GetPathToExecutionCache(string pathToScript) { - var pathToTempFolder = Path.GetDirectoryName(Dotnet.Script.DependencyModel.ProjectSystem.FileUtils.GetPathToScriptTempFolder(pathToScript)); + var pathToTempFolder = Dotnet.Script.DependencyModel.ProjectSystem.FileUtils.GetPathToScriptTempFolder(pathToScript); var pathToExecutionCache = Path.Combine(pathToTempFolder, "execution-cache"); return pathToExecutionCache; } diff --git a/src/Dotnet.Script.Tests/ScaffoldingTests.cs b/src/Dotnet.Script.Tests/ScaffoldingTests.cs index c5dcd506..0c8f48cf 100644 --- a/src/Dotnet.Script.Tests/ScaffoldingTests.cs +++ b/src/Dotnet.Script.Tests/ScaffoldingTests.cs @@ -34,6 +34,24 @@ public void ShouldInitializeScriptFolder() } } + [Fact] + public void ShouldInitializeScriptFolderContainingWhitespace() + { + using (var scriptFolder = new DisposableFolder()) + { + var path = Path.Combine(scriptFolder.Path, "Folder with whitespace"); + Directory.CreateDirectory(path); + + var (output, exitCode) = ScriptTestRunner.Default.Execute("init", path); + + Assert.Equal(0, exitCode); + Assert.DoesNotContain("No such file or directory", output, StringComparison.OrdinalIgnoreCase); + Assert.True(File.Exists(Path.Combine(path, "main.csx"))); + Assert.True(File.Exists(Path.Combine(path, "omnisharp.json"))); + Assert.True(File.Exists(Path.Combine(path, ".vscode", "launch.json"))); + } + } + [OnlyOnUnixFact] public void ShouldRegisterToRunCsxScriptDirectly() { diff --git a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs index 2c41ceaf..62c84cb8 100644 --- a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs +++ b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs @@ -351,6 +351,13 @@ public void ShouldThrowMeaningfulErrorMessageWhenDependencyIsNotFound() } } + [Fact] + public void ShouldHandleIssue613() + { + var result = ScriptTestRunner.Default.ExecuteFixture("Issue613"); + Assert.Equal(0, result.exitCode); + } + [Fact] public void ShouldHandleIssue235() { diff --git a/src/Dotnet.Script.Tests/TestFixtures/Issue613/Issue613.csx b/src/Dotnet.Script.Tests/TestFixtures/Issue613/Issue613.csx new file mode 100644 index 00000000..bbe48cd4 --- /dev/null +++ b/src/Dotnet.Script.Tests/TestFixtures/Issue613/Issue613.csx @@ -0,0 +1,18 @@ +#r "nuget: System.Text.Encoding.CodePages, 5.0.0" + +public class Script +{ + public static void Run() + { + try + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + } + catch (Exception ex) + { + System.Console.WriteLine(ex.ToString()); + } + } +} + +Script.Run(); \ No newline at end of file diff --git a/src/Dotnet.Script/Dotnet.Script.csproj b/src/Dotnet.Script/Dotnet.Script.csproj index 34bb80ce..7cbd6249 100644 --- a/src/Dotnet.Script/Dotnet.Script.csproj +++ b/src/Dotnet.Script/Dotnet.Script.csproj @@ -1,7 +1,7 @@  Dotnet CLI tool allowing you to run C# (CSX) scripts. - 1.0.1 + 1.1.0 filipw Dotnet.Script net5.0;netcoreapp2.1;netcoreapp3.1 @@ -20,11 +20,13 @@ false true latest + true + ../dotnet-script.snk - + - + diff --git a/src/dotnet-script.snk b/src/dotnet-script.snk new file mode 100644 index 00000000..23f209ff Binary files /dev/null and b/src/dotnet-script.snk differ diff --git a/src/omnisharp.json b/src/omnisharp.json deleted file mode 100644 index 922da146..00000000 --- a/src/omnisharp.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "fileOptions": { - "systemExcludeSearchPatterns": [ - "**/TestFixtures/**/*.csx", - "**/ScriptPackages/**/*.csx" - ], - "userExcludeSearchPatterns": [] - } -}