Closed naratteu closed 2 months ago
Ensure that .NET Framework 4.x targeting pack is selected and installed For .NET Core and .NET 5+ projects, you might need to explicitly add the System.CodeDom package to your project.
Edit the .csproj file of the project where the T4 template is used. Add the System.CodeDom package reference:
Restore the packages before build dotnet restore
I ran the command in codespace and got the following error:
cd ./src/T4.SourceGenerators.Example
dotnet --version
8.0.301
dotnet add package System.CodeDom --version 6.0.0
dotnet restore
dotnet build
👋 Welcome to Codespaces! You are on our default image.
- It includes runtimes and tools for Python, Node.js, Docker, and more. See the full list here: https://aka.ms/ghcs-default-image
- Want to use a custom image instead? Learn more here: https://aka.ms/configure-codespace
🔍 To explore VS Code to its fullest, search using the Command Palette (Cmd/Ctrl + Shift + P or F1).
📝 Edit away, run your app as usual, and we'll automatically make it available for you to access.
@naratteu ➜ /workspaces/T4.SourceGenerator (master) $ cd ./src/T4.SourceGenerators.Example
@naratteu ➜ /workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example (master) $ dotnet --version
8.0.301
@naratteu ➜ /workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example (master) $ dotnet add package System.CodeDom --version 6.0.0
Welcome to .NET 8.0!
---------------------
SDK Version: 8.0.301
Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate, view the instructions: https://aka.ms/dotnet-https-linux
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
Determining projects to restore...
Writing /tmp/tmpPgA8q7.tmp
info : X.509 certificate chain validation will use the fallback certificate bundle at '/usr/share/dotnet/sdk/8.0.301/trustedroots/codesignctl.pem'.
info : X.509 certificate chain validation will use the fallback certificate bundle at '/usr/share/dotnet/sdk/8.0.301/trustedroots/timestampctl.pem'.
info : Adding PackageReference for package 'System.CodeDom' into project '/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/T4.SourceGenerators.Example.csproj'.
info : Restoring packages for /workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/T4.SourceGenerators.Example.csproj...
info : GET https://api.nuget.org/v3-flatcontainer/asyncfixer/index.json
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.codeanalysis.analyzers/index.json
info : GET https://api.nuget.org/v3-flatcontainer/system.codedom/index.json
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.codeanalysis.netanalyzers/index.json
info : GET https://api.nuget.org/v3-flatcontainer/polysharp/index.json
info : GET https://api.nuget.org/v3-flatcontainer/qowaiv.analyzers.csharp/index.json
info : GET https://api.nuget.org/v3-flatcontainer/sonaranalyzer.csharp/index.json
info : GET https://api.nuget.org/v3-flatcontainer/t4.sourcegenerator/index.json
info : GET https://api.nuget.org/v3-flatcontainer/dotnetprojectfile.analyzers/index.json
info : OK https://api.nuget.org/v3-flatcontainer/t4.sourcegenerator/index.json 862ms
info : OK https://api.nuget.org/v3-flatcontainer/asyncfixer/index.json 876ms
info : GET https://api.nuget.org/v3-flatcontainer/t4.sourcegenerator/1.2.0/t4.sourcegenerator.1.2.0.nupkg
info : GET https://api.nuget.org/v3-flatcontainer/asyncfixer/1.6.0/asyncfixer.1.6.0.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/qowaiv.analyzers.csharp/index.json 882ms
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.codeanalysis.netanalyzers/index.json 883ms
info : GET https://api.nuget.org/v3-flatcontainer/qowaiv.analyzers.csharp/0.0.8/qowaiv.analyzers.csharp.0.0.8.nupkg
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.codeanalysis.netanalyzers/8.0.0-preview1.23165.1/microsoft.codeanalysis.netanalyzers.8.0.0-preview1.23165.1.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/asyncfixer/1.6.0/asyncfixer.1.6.0.nupkg 7ms
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.codeanalysis.analyzers/index.json 890ms
info : OK https://api.nuget.org/v3-flatcontainer/system.codedom/index.json 890ms
info : OK https://api.nuget.org/v3-flatcontainer/dotnetprojectfile.analyzers/index.json 885ms
info : GET https://api.nuget.org/v3-flatcontainer/dotnetprojectfile.analyzers/1.1.0/dotnetprojectfile.analyzers.1.1.0.nupkg
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.codeanalysis.analyzers/3.11.0-beta1.23420.2/microsoft.codeanalysis.analyzers.3.11.0-beta1.23420.2.nupkg
info : GET https://api.nuget.org/v3-flatcontainer/system.codedom/6.0.0/system.codedom.6.0.0.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/polysharp/index.json 891ms
info : GET https://api.nuget.org/v3-flatcontainer/polysharp/1.13.2/polysharp.1.13.2.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/system.codedom/6.0.0/system.codedom.6.0.0.nupkg 3ms
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.codeanalysis.analyzers/3.11.0-beta1.23420.2/microsoft.codeanalysis.analyzers.3.11.0-beta1.23420.2.nupkg 10ms
info : OK https://api.nuget.org/v3-flatcontainer/polysharp/1.13.2/polysharp.1.13.2.nupkg 7ms
info : OK https://api.nuget.org/v3-flatcontainer/sonaranalyzer.csharp/index.json 911ms
info : GET https://api.nuget.org/v3-flatcontainer/sonaranalyzer.csharp/9.12.0.78982/sonaranalyzer.csharp.9.12.0.78982.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/sonaranalyzer.csharp/9.12.0.78982/sonaranalyzer.csharp.9.12.0.78982.nupkg 8ms
info : OK https://api.nuget.org/v3-flatcontainer/t4.sourcegenerator/1.2.0/t4.sourcegenerator.1.2.0.nupkg 223ms
info : OK https://api.nuget.org/v3-flatcontainer/qowaiv.analyzers.csharp/0.0.8/qowaiv.analyzers.csharp.0.0.8.nupkg 842ms
info : OK https://api.nuget.org/v3-flatcontainer/dotnetprojectfile.analyzers/1.1.0/dotnetprojectfile.analyzers.1.1.0.nupkg 874ms
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.codeanalysis.netanalyzers/8.0.0-preview1.23165.1/microsoft.codeanalysis.netanalyzers.8.0.0-preview1.23165.1.nupkg 897ms
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.app.ref/index.json
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.host.linux-x64/index.json
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.ref/index.json
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.host.linux-x64/index.json 217ms
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.app.ref/index.json 220ms
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.ref/index.json 854ms
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.ref/7.0.20/microsoft.netcore.app.ref.7.0.20.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.ref/7.0.20/microsoft.netcore.app.ref.7.0.20.nupkg 3ms
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.host.linux-x64/7.0.20/microsoft.netcore.app.host.linux-x64.7.0.20.nupkg
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.app.ref/7.0.20/microsoft.aspnetcore.app.ref.7.0.20.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.host.linux-x64/7.0.20/microsoft.netcore.app.host.linux-x64.7.0.20.nupkg 5ms
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.app.ref/7.0.20/microsoft.aspnetcore.app.ref.7.0.20.nupkg 101ms
info : Installed Microsoft.NETCore.App.Host.linux-x64 7.0.20 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/microsoft.netcore.app.host.linux-x64/7.0.20 with content hash N4JRZmBDCpO2UYSOR6CtrtBeOjSvx0cqYmYYDRVjPlu/FIVyCpN3VWMbdzjMfMmKrrMwt1sCEDn0cAuU6/MuVg==.
info : Installed Microsoft.AspNetCore.App.Ref 7.0.20 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/microsoft.aspnetcore.app.ref/7.0.20 with content hash dF49BcC6naWUSlIN+WGwhTxLIxlvQzDa8m7iWg5mHc4IIrtnR4oO+2Se808pA4w80yjEVA2/2c/oN3BTVFp4Ew==.
info : Installed SonarAnalyzer.CSharp 9.12.0.78982 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/sonaranalyzer.csharp/9.12.0.78982 with content hash QxhfMFCNeZWP3gP/R8QM3MuDWm+Esj8Lt3oD61tid5TPuqsaKJtwMZNZWE2FOqqGuKlu3805o8MlkTWBL75skA==.
info : Installed Microsoft.NETCore.App.Ref 7.0.20 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/microsoft.netcore.app.ref/7.0.20 with content hash Ek577ILlxN7dJToJhvoO+u0jPG9iPHyUgHcGTDdMut8hzSxahbZBxE8gYK4Xq7/466ujXVXtv0iMvH7IGuIucQ==.
info : Installed System.CodeDom 6.0.0 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/system.codedom/6.0.0 with content hash CPc6tWO1LAer3IzfZufDBRL+UZQcj5uS207NHALQzP84Vp/z6wF0Aa0YZImOQY8iStY0A2zI/e3ihKNPfUm8XA==.
info : Installed T4.SourceGenerator 1.2.0 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/t4.sourcegenerator/1.2.0 with content hash k4mU0x6rfqdS6v3UU/zokB/yaD6n6aQp4o6VRvLq+1LHCQ77fQXSGh8RPMXNJNNchHYgioc99lv05E3gZVzcuQ==.
info : Installed Qowaiv.Analyzers.CSharp 0.0.8 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/qowaiv.analyzers.csharp/0.0.8 with content hash tjFfl6jKReGoByqA0xahjuQ2+5vA4UPTvngerbuDESuFSO0rshk9RbPaJZFAMWq+ejl/ZgjhwgUmrg+oDghkAw==.
info : Installed AsyncFixer 1.6.0 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/asyncfixer/1.6.0 with content hash /Xfs9H3UMfEv64cwT+C/JrTRp4w08BmPuFbj0ageadCHpx6rxYJxAU2C6sEqRFG22xmGk5cX9ewzoiiehWVHOw==.
info : Installed PolySharp 1.13.2+0596138b111ff552137684c6f7c3373805d2e3d2 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/polysharp/1.13.2 with content hash XwNhfkr7IeUiH8AE4pzob8YioxfL6nxgAx+fHEeWCObY/NZuBMfWLh39FznXbneKvagiqeeI7quIvZ6P1eVaEA==.
info : Installed DotNetProjectFile.Analyzers 1.1.0 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/dotnetprojectfile.analyzers/1.1.0 with content hash RSyxlmgaaIbITfs9XHb9hGttziFhS9heOBSibf+lKSrdOhYpSJEuLipWz1HQ+GAZpojOfiBS8ao7tQuhVCuZuw==.
info : Installed Microsoft.CodeAnalysis.Analyzers 3.11.0-beta1.23420.2 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/microsoft.codeanalysis.analyzers/3.11.0-beta1.23420.2 with content hash TXazD+ljZOOOwnDTl4+TmkbvI01iGq1/vfX42F7D8SvjmtgHPIDCTyEn/epIq9q9boNbPIKD1LhD0usQ6yoRAg==.
info : Installed Microsoft.CodeAnalysis.NetAnalyzers 8.0.0-preview1.23165.1 from https://api.nuget.org/v3/index.json to /home/codespace/.nuget/packages/microsoft.codeanalysis.netanalyzers/8.0.0-preview1.23165.1 with content hash 0OwNin5K0hEXpV3WU8AwtZ48Dt5jLTu4wGjHsMfnstJ1HJj/qL/rZSCtLiZPqOgR2MyAfp28uNw5AEuJpLMggA==.
info : GET https://api.nuget.org/v3/vulnerabilities/index.json
info : OK https://api.nuget.org/v3/vulnerabilities/index.json 4ms
info : GET https://api.nuget.org/v3-vulnerabilities/2024.06.28.05.31.02/vulnerability.base.json
info : GET https://api.nuget.org/v3-vulnerabilities/2024.06.28.05.31.02/2024.06.28.23.31.03/vulnerability.update.json
info : OK https://api.nuget.org/v3-vulnerabilities/2024.06.28.05.31.02/vulnerability.base.json 3ms
info : OK https://api.nuget.org/v3-vulnerabilities/2024.06.28.05.31.02/2024.06.28.23.31.03/vulnerability.update.json 2ms
info : Package 'System.CodeDom' is compatible with all the specified frameworks in project '/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/T4.SourceGenerators.Example.csproj'.
info : PackageReference for package 'System.CodeDom' version '6.0.0' added to file '/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/T4.SourceGenerators.Example.csproj'.
info : Generating MSBuild file /workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/obj/T4.SourceGenerators.Example.csproj.nuget.g.props.
info : Generating MSBuild file /workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/obj/T4.SourceGenerators.Example.csproj.nuget.g.targets.
info : Writing assets file to disk. Path: /workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/obj/project.assets.json
log : Restored /workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/T4.SourceGenerators.Example.csproj (in 6.58 sec).
@naratteu ➜ /workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example (master) $ dotnet restore
Determining projects to restore...
All projects are up-to-date for restore.
@naratteu ➜ /workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example (master) $ dotnet build
Determining projects to restore...
All projects are up-to-date for restore.
/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/Templates/Foo.tt(1,1): error TF0003: Exception thrown while generating code for T4 template '/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/Templates/Foo.tt': System.AggregateException: One or more errors occurred. (The value cannot be an empty string. (Parameter 'assemblyName')) [/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/T4.SourceGenerators.Example.csproj]
/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/Program.cs(1,26): error CS0234: The type or namespace name 'Example' does not exist in the namespace 'T4.SourceGenerator' (are you missing an assembly reference?) [/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/T4.SourceGenerators.Example.csproj]
Build FAILED.
/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/Templates/Foo.tt(1,1): error TF0003: Exception thrown while generating code for T4 template '/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/Templates/Foo.tt': System.AggregateException: One or more errors occurred. (The value cannot be an empty string. (Parameter 'assemblyName')) [/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/T4.SourceGenerators.Example.csproj]
/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/Program.cs(1,26): error CS0234: The type or namespace name 'Example' does not exist in the namespace 'T4.SourceGenerator' (are you missing an assembly reference?) [/workspaces/T4.SourceGenerator/src/T4.SourceGenerators.Example/T4.SourceGenerators.Example.csproj]
0 Warning(s)
2 Error(s)
Time Elapsed 00:00:03.93
can you check and share your foo.tt file I think it is missing the 'AssemblyName' parameter. it should be something like <#@ assembly name="System.Core" #>
Make sure that all necessary project references are added in the T4.SourceGenerator project file check program.cs has the line
using T4.SourceGenerator.Example;
then try
dotnet clean dotnet restore dotnet build
it will be better if you can help make me understand your codebase structure.
This issue is caused by differences in the development environment, and it doesn't make sense to modify the examples included in this repository..
After some investigation I at least figured out some differences. It appears that while building it in Visual Studio, Mono.TextTemplating seems to be referring .NET Framework 4.8 dependencies:
C:\Users\<UserName>\AppData\Local\Temp\VBCSCompiler\AnalyzerAssemblyLoader\cd574787eb8c47c1b1eb529cbd936198\c4728bbb-95e2-4567-9206-37ed40d5ad4b\Mono.TextTemplating.dll
C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
While dotnet run
makes it use the modern .NET (Core) libraries:
C:\Users\<UserName>\AppData\Local\Temp\VBCSCompiler\AnalyzerAssemblyLoader\ca8bb02e21a4421d83fb19bb00bce4cc\c4728bbb-95e2-4567-9206-37ed40d5ad4b\Mono.TextTemplating.dll
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Private.Uri.dll
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Private.CoreLib.dll
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Private.CoreLib.dll
It's working fine. I'll wait for the new version deployment. Thank you 😄
> cd ~
> git clone https://github.com/CptWesley/T4.SourceGenerator.git
> cd T4*
> git switch alternate-2
> cd src/T4*r
> dotnet build -c Release
> cd ../T4*e
> dotnet nuget add source ~/T4.SourceGenerator/src/T4.SourceGenerator/bin/Release
> dotnet run
Hello, 1764!
Running through Visual Studio worked fine, but when trying to build from the command line, the following error occurs.