Closed UweKeim closed 23 hours ago
Hey Uwe, I am not sure what is happening, but I can definitely look at it. I assume this script will trigger the problem:
//css_include global-usings
//css_nuget SharpZipLib
typeof(ICSharpCode.SharpZipLib.Zip.FastZip).print();
Can you also give me the context - the .NET SDK version
I've downloaded the latest source code of CS-Script and tried to debug it.
Here are some random thoughts.
When debugging through this section, the generated CSPROJ file, passed to dotnet restore
and dotnet publish
looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>_59ffa5d1_390c_4d8c_9aa1_4b9064de83c7</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Svg" Version="3.2.3" />
<PackageReference Include="morelinq" Version="*" />
<PackageReference Include="Newtonsoft.Json" Version="*" />
<PackageReference Include="NuGet.Versioning" Version="*" />
<PackageReference Include="QuickUploader.WebApiAccessor" Version="*" />
<PackageReference Include="RestSharp" Version="*" />
<PackageReference Include="SharpZipLib" Version="*" />
<PackageReference Include="ZetaDeployer.RuntimeUploader" Version="*" />
<PackageReference Include="ZetaShortPaths" Version="*" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="*" />
</ItemGroup>
</Project>
The CSPROJ looks correct to me (the file references to my script files are still missing, but I do think this is OK).
After running the dotnet publish
command, the output folder is nearly empty:
C:\USERS\UKEIM\APPDATA\LOCAL\TEMP\CSSCRIPT.CORE\NUGET\59FFA5D1-390C-4D8C-9AA1-4B9064DE83C7
│ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.csproj
│ Class1.cs
│
├───bin
│ └───Release
│ └───net9.0
│ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.deps.json
│ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.dll
│ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.pdb
│
├───obj
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.csproj.nuget.dgspec.json
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.csproj.nuget.g.props
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.csproj.nuget.g.targets
│ │ project.assets.json
│ │ project.nuget.cache
│ │
│ └───Release
│ └───net9.0
│ │ .NETCoreApp,Version=v9.0.AssemblyAttributes.cs
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.AssemblyInfo.cs
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.AssemblyInfoInputs.cache
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.assets.cache
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.csproj.CoreCompileInputs.cache
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.csproj.FileListAbsolute.txt
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.dll
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.GeneratedMSBuildEditorConfig.editorconfig
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.GlobalUsings.g.cs
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.pdb
│ │ PublishOutputs.7074de2593.txt
│ │
│ ├───ref
│ │ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.dll
│ │
│ └───refint
│ 59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.dll
│
└───publish
59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.deps.json
59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.dll
59ffa5d1-390c-4d8c-9aa1-4b9064de83c7.pdb
Therefore, this call (which contains a bug, IMO) returns an empty allRefAssemblies
array.
Later on, it generates the final CSPROJ file to send to the compiler:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>do-build-all</AssemblyName>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>TRACE;NETCORE;CS_SCRIPT</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Threading.dll">
<HintPath>C:\Users\ukeim\.nuget\packages\System.Threading\4.0.11\lib\netcore50\System.Threading.dll</HintPath>
</Reference>
<Reference Include="Aspose.Cells.dll">
<HintPath>C:\P\zp-17.0\ZetaProducerContent\Development\Projects\Build\Helper\Aspose.Cells.dll</HintPath>
</Reference>
<Reference Include="System.Linq.dll">
<HintPath>C:\Users\ukeim\.nuget\packages\System.Linq\4.1.0\lib\netcore50\System.Linq.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json.dll">
<HintPath>C:\Users\ukeim\.nuget\packages\newtonsoft.json\9.0.1\lib\netstandard1.0\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="MoreLinq.dll">
<HintPath>C:\Users\ukeim\.nuget\packages\morelinq\4.3.0\lib\netstandard2.1\MoreLinq.dll</HintPath>
</Reference>
<Reference Include="Svg.dll">
<HintPath>C:\Users\ukeim\.nuget\packages\svg\3.2.3\lib\netcoreapp3.0\Svg.dll</HintPath>
</Reference>
<Reference Include="NuGet.Versioning.dll">
<HintPath>C:\Users\ukeim\.nuget\packages\nuget.versioning\6.9.1\lib\netstandard2.0\NuGet.Versioning.dll</HintPath>
</Reference>
<Reference Include="cscs.dll">
<HintPath>C:\Ablage\cs-script-master\src\cscs\bin\Debug\net8.0\cscs.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="C:\P\zp-17.0\ZetaProducerContent\Development\Projects\Build\do-build-all.cs" Link="do-build-all.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\Afx.cs" Link="Afx.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\AppOfflineUtilities.cs" Link="AppOfflineUtilities.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\BuildUtilities.cs" Link="BuildUtilities.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\CompilationUtilities.cs" Link="CompilationUtilities.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\FileSyncUtilities.cs" Link="FileSyncUtilities.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\FileUtilities.cs" Link="FileUtilities.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\FolderUtilities.cs" Link="FolderUtilities.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\FolderXCopy.cs" Link="FolderXCopy.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\FolderXCopyUtilities.cs" Link="FolderXCopyUtilities.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\FolderZip.cs" Link="FolderZip.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\Logging.cs" Link="Logging.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\ProcessUtilities.cs" Link="ProcessUtilities.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\QuickUploaderUtilities.cs" Link="QuickUploaderUtilities.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\SpecialFolders.cs" Link="SpecialFolders.cs" />
<Compile Include="C:\P\zp-17.0\_References\Submodules\zeta-shared-ci-assets\DevelopmentTools\CentralScripts\StringUtilities.cs" Link="StringUtilities.cs" />
<Compile Include="C:\P\zp-17.0\ZetaProducerContent\Development\Projects\Build\Helper\ExcelImport.cs" Link="ExcelImport.cs" />
<Compile Include="C:\P\zp-17.0\ZetaProducerContent\Development\Projects\Build\Helper\FileHelper.cs" Link="FileHelper.cs" />
<Compile Include="C:\P\zp-17.0\ZetaProducerContent\Development\Projects\Build\Helper\ModelHelper.cs" Link="ModelHelper.cs" />
<Compile Include="C:\P\zp-17.0\ZetaProducerContent\Development\Projects\Build\Helper\ProjektvorlageModel.cs" Link="ProjektvorlageModel.cs" />
<Compile Include="C:\P\zp-17.0\ZetaProducerContent\Development\Projects\Build\Helper\ProjektvorlageProcessor.cs" Link="ProjektvorlageProcessor.cs" />
<Compile Include="C:\P\zp-17.0\ZetaProducerContent\Development\Projects\Build\Helper\TagsController.cs" Link="TagsController.cs" />
<Compile Include="C:\Users\ukeim\AppData\Local\Temp\csscript.core\cache\475058790\do-build-all.attr.g.cs" Link="do-build-all.attr.g.cs" />
</ItemGroup>
</Project>
Here, to my surprise, the initial (correct) <PackageReference..>
-Entries are not present anymore.
I will have a look and compare the packages folder structure. A few points:
having no reference to your script. Correct. This project was only created to force .NET to aggregate all DLLs and then reference them from the script
I actually managed to compile my script sample script:
D:\dev\support>css -config:set:LegacyNugetSupport=false
set: LegacyNugetSupport: False
D:\dev\support>css test Restoring packages... Mapping packages to assemblies... {ICSharpCode.SharpZipLib.Zip.FastZip} .Assembly = {ICSharpCode.SharpZipLib, Version=1.4.2.13, Culture=neutral, PublicKeyToken=1b03e6acf1164f73} .AssemblyQualifiedName = "ICSharpCode.SharpZipLib.Zip.FastZip, ICSharpCode.SharpZipLib, Version=1.4.2.13, Culture=neutral, PublicKeyToken=1b03e6acf1164f73" .Attributes = Public, BeforeFieldInit .BaseType = {object} .ContainsGenericParameters = False . . .
Will let you know the folder structure comparison outcome.
Thanks, @oleg-shilo.
In the final CSPROJ that gets sent to the dotnet build
, the <PackageReference ...>
entries are not present anymore and replaced by the assemblies that you looked up.
Do I have an option to skip the whole "self-made" lookup mechanism and simply have all (correctly!) detected <PackageReference ...>
entires be present in the final CSPROJ file?
Can you also give me the context - the .NET SDK version
I'm having the following .NET SDKs on my machine:
C:\Users\ukeim>dotnet --list-sdks
6.0.428 [C:\Program Files\dotnet\sdk]
7.0.120 [C:\Program Files\dotnet\sdk]
7.0.410 [C:\Program Files\dotnet\sdk]
9.0.100 [C:\Program Files\dotnet\sdk]
I could also assemble a test script if it would help you.
Personally, I do think that is something that happend on my machine that suddenly breaks the scripts; I just don't know what.
I assume this script will trigger the problem:
//css_include global-usings //css_nuget SharpZipLib typeof(ICSharpCode.SharpZipLib.Zip.FastZip).print();
To my surprise, this compiles successfully on my machine 😢.
OK, I do think I figured it out:
My script also included another file //css_import Helper\ProjektvorlageProcessor
that contains this code:
//css_nuget -force:3600 -ver:3.2.3 -ng:"-Source https://nuget.org/api/v2/" Svg
//css_nuget -force:3600 -ng:"-Source https://nuget.org/api/v2/" Microsoft.SqlServer.Compact
This was a fragment from when I used the old CS-Script that runs with .NET Framework.
After changing it to this:
//css_nuget Svg
//css_nuget Microsoft.SqlServer.Compact
My script compiles successfully.
I still don't know why the "old" NuGet reference syntax causes this behavior, but at least I do have an explanation and a fix now.
Sorry for bothering you with my problems that I caused by myself.
I leave this here to publicly shame myself and to maybe help someone in the future (possibly including myself).
...I leave this here to publicly shame myself ...
Not at all. This is a struggle that everyone would have to go through given the circumstances. I know I have been there once or twice. Likely your old //css_nuget
is causing the version clash. But most likely it sets the local source and then it leads to dependency confusion of a sort.
I think it makes sense to update the project generation output to help with the troubleshooting. Currently, this is what it does:
But it should include the nuget packages requested.
Also something similar might be printed in the output when the packages are being resolved. Currently it simply says "Resolving packages..."
I am changing this issue to the "Enhancement".
This is how it is going to be in the next release:
This is a great enhancement, Oleg. Thank you very much 😊
I also updated the new restore algorithm which is to print the packages so it can help with the CI logs.
Note, the legacy algorithm already prints the output on nuget.exe. So there is no need to print the package names from the cs-script since nuget.exe does it anyway.
Suddenly, out of nowhere, I get errors because it seems CS-Script does not recognize all referenced NuGet packages anymore.
My script worked well before.
I tried this directly on the command line:
Then, the beginning output of the last command is:
It starts promising, as it correctly detects "sharpziplib".
The output continues:
As you can see, the detected references do not include "sharpziplib" despite having
//css_nuget SharpZipLib
in my "do-build-all.cs" script.The output then continues:
This did work before and now suddenly does not work.
I'm rather clueless and I thought this happened before but found no issue here so far to see what helped back then.
To add more information, my "C:\Users\ukeim.nuget\packages\sharpziplib" folder contains this structure:
My question:
Do you have any idea what might go on or what might have happened?