Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derived symbol value is empty when it is in Symbol geneator #6291

Closed
chunyu3 opened this issue Mar 21, 2023 · 7 comments
Closed

Derived symbol value is empty when it is in Symbol geneator #6291

chunyu3 opened this issue Mar 21, 2023 · 7 comments
Assignees
Labels
Iteration:2023April triaged The issue was evaluated by the triage team, placed on correct area, next action defined.

Comments

@chunyu3
Copy link

chunyu3 commented Mar 21, 2023

in dotnet 7.0.2, When we reference a derived symbol in a symbol generator, the generated symbol value does not contain the derived symbol.
run
dotnet new *** --ClientName test

The value of PackageName :
Actual: Package.
expected: Package.Test

It works fine in dotnet 3.1.

"symbols": {
"clientName": {
      "type": "parameter",
      "datatype": "text",
      "isRequired": true,
      "description": "client name"
    },
"ClientNameCapitalCase": {
      "type": "derived",
      "datatype": "text",
      "valueSource": "clientName",
      "valueTransform": "firstUpperCase",
      "replaces": "Template"
    },
"PackageName": {
      "type": "generated",
      "generator": "join",
      "parameters": {
        "symbols": [
          {
            "type": "const",
            "value": "Package"
          },
          {
            "type": "ref",
            "value": "ClientNameCapitalCase"
          }
        ],
        "separator": "."
      },
    },
}
@YuliiaKovalova
Copy link
Member

Hi @chunyu3,

Thank you for reporting the bug.
We are investigating the issue.

@GangWang01
Copy link
Member

It was reproduced with dotnet 7.0.2. Root cause is the wrong order processing generated symbol and computed symbol at

MacrosOperationConfig? macroProcessor = null;
if (runConfig.GeneratedSymbolMacros != null)
{
macroProcessor = new MacrosOperationConfig();
macroProcessor.ProcessMacros(environmentSettings, runConfig.GeneratedSymbolMacros, variableCollection);
}
if (runConfig.ComputedMacros != null)
{
macroProcessor ??= new MacrosOperationConfig();
macroProcessor.ProcessMacros(environmentSettings, runConfig.ComputedMacros, variableCollection);
}
. Release/7.0.3xx should also have this problem.

This issue was fixed in PR #5223 that refactored at

bool deterministicMode = IsDeterministicModeEnabled(environmentSettings);
foreach (BaseMacroConfig config in runConfig.ComputedMacros)
{
try
{
if (deterministicMode)
{
config.EvaluateDeterministically(environmentSettings, variables);
}
else
{
config.Evaluate(environmentSettings, variables);
}
}
catch (Exception ex)
{
throw new MacroProcessingException(config, ex);
}
}
if (!runConfig.GeneratedSymbolMacros.Any())
{
return;
}
Dictionary<string, IGeneratedSymbolMacro> generatedSymbolMacros = environmentSettings.Components.OfType<IGeneratedSymbolMacro>().ToDictionary(m => m.Type, m => m);
foreach (IGeneratedSymbolConfig config in runConfig.GeneratedSymbolMacros)
{
if (generatedSymbolMacros.TryGetValue(config.Type, out IGeneratedSymbolMacro generatedSymbolMacro))
{
try
{
if (deterministicMode && generatedSymbolMacro is IDeterministicModeMacro<IGeneratedSymbolConfig> deterministicMacro)
{
deterministicMacro.EvaluateDeterministically(environmentSettings, variables, config);
}
else
{
generatedSymbolMacro.Evaluate(environmentSettings, variables, config);
}
}
//TemplateAuthoringException means that config was invalid, just pass it.
catch (Exception ex) when (ex is not TemplateAuthoringException)
{
throw new MacroProcessingException(config, ex);
}
}
else
{
environmentSettings.Host.Logger.LogWarning(LocalizableStrings.MacroProcessor_Warning_UnknownMacro, config.VariableName, config.Type);
}
}
. dotnet 8.0.100-preview.2 has the fix.

BTW, .NET 6.0 doesn't have this problem.

@YuliiaKovalova
Copy link
Member

Hi @chunyu3,

Could you specify the urgency of this fix for your tasks? Do you have a workaround?

@chunyu3
Copy link
Author

chunyu3 commented Apr 3, 2023

Thanks @YuliiaKovalova and @GangWang01 for the quick resolve. Yes, it will block our project to generate the correct project via template and it has current no workaround now.
@YuliiaKovalova , when can I get a release version contains this resolution? Thanks. And is it possible to release a hotfix for .Net 7?

@YuliiaKovalova
Copy link
Member

Hi @chunyu3,

We are discussing possible solutions behind the scene. I will give you more information once know more.

@YuliiaKovalova
Copy link
Member

Hi @chunyu3 ,

The issue is fixed for release/7.0.2xx.
Please expect to receive these changes with the next patch - preliminary in the middle of June.
Thank you for your patience!

Best Regards,
Yuliia Kovalova

@chunyu3
Copy link
Author

chunyu3 commented May 5, 2023

7.0.2

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Iteration:2023April triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Projects
None yet
Development

No branches or pull requests

3 participants