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

Support for T4ParameterValues #78

Open
ltrzesniewski opened this issue Nov 16, 2024 · 0 comments
Open

Support for T4ParameterValues #78

ltrzesniewski opened this issue Nov 16, 2024 · 0 comments

Comments

@ltrzesniewski
Copy link

Would it be possible to get external parameter values using T4ParameterValues items and <#@ parameter #> directives? I'm looking to get a value from a MSBuild property.

Maybe I'm wrong, but as far as I can tell, properties are generated for declared parameters, but they're always null.

If I want to declare a RefAsmPath parameter, the generated Initialize method looks like this (decompiled):

public virtual void Initialize()
{
	if (((TextTransformation)this).Errors.HasErrors)
		return;
	bool RefAsmPathValueAcquired = false;
	if (((TextTransformation)this).Session.ContainsKey("RefAsmPath"))
	{
		_RefAsmPathField = (string)((TextTransformation)this).Session["RefAsmPath"];
		RefAsmPathValueAcquired = true;
	}
	if (!RefAsmPathValueAcquired)
	{
		string parameterValue = Host.ResolveParameterValue("Property", "PropertyDirectiveProcessor", "RefAsmPath");
		if (!string.IsNullOrEmpty(parameterValue))
		{
			TypeConverter tc = TypeDescriptor.GetConverter(typeof(string));
			if (tc != null && tc.CanConvertFrom(typeof(string)))
			{
				_RefAsmPathField = (string)tc.ConvertFrom(parameterValue);
				RefAsmPathValueAcquired = true;
			}
			else
				((TextTransformation)this).Error("The type 'System.String' of the parameter 'RefAsmPath' did not match the type of the data passed to the template.");
		}
	}
	if (!RefAsmPathValueAcquired)
	{
		object data = CallContext.LogicalGetData("RefAsmPath");
		if (data != null)
			_RefAsmPathField = (string)data;
	}
}

Except...

  • Initialize is never called
  • Session is null, so Initialize would throw anyway
  • Host.ResolveParameterValue always returns string.Empty
  • CallContext.LogicalGetData("RefAsmPath") returns null...

So I guess there's a lot to do in order to add support 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant