Reputation: 1
I want to get access to variable from .vcsproj at compile time.
main.cpp:
using namespace System;
using namespace System::Reflection;
using namespace cli;
[AttributeUsageAttribute(AttributeTargets::Assembly)]
ref class Attr sealed : public Attribute {
public:
Attr(String^ _value) { value = _value; }
String^ value;
};
int main()
{
Assembly^ assembly = Assembly::GetEntryAssembly();
array<Object^>^ assemblyArray = assembly->GetCustomAttributes(Attr::typeid, true);
Attr^ attr = dynamic_cast<Attr^>(assemblyArray->GetValue(0));
String^ value = attr->value; // value != "myValue"
return 0;
}
Fragment of VisualStudio project file:
project_name.vcsproj.
<ItemGroup>
<AssemblyAttribute Include="ClassLibrary1.Attr">
<_Parameter1>"myValue"</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
Obviously I don't understand enough how attributes works but I can't even reproduce solution from this post. How to make it work?
I tried this solution but somehow it doesn't work for me..
Upvotes: 0
Views: 21