I'm using IronPython for my project. The setup is following:
Project.Main
- MyProject.Python
- IronPython package
Project.Main has a class called Community
that is one of the main classes. It is used everywhere.
Now has IronPython a namespace called Community.CsharpSqlite with a class called Sqlite3.
- I do not need to reference this class within MyProject.Main
- I am not using any classes directly from the IronPython package within MyProject.Main
- I only refer to wrapper classes in MyProject.Python.
All my code doesn't compile anymore though because I'm getting:
Error CS0118 'Community' is a namespace but is used like a type
This is a very large project and I do not want to start prefixing all my references to the Community class with a namespace prefix.
- Is there any workaround?
- Can I expose the IronPython namespaces only to MyProject.Python?
- I tried both Aliases and the PrivateAssets option but I get a warning symbol within the solution explorer and it does not seem to work (still the CS0118)
- see https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files
Example project:
https://www.dropbox.com/s/hayi3a4ctrh8rlx/NamespaceProblem.zip?dl=0
Update:
To fix this we need to edit the ConsoleApp1
.csproj
file and add at the bottom:Then we can load the new modified external alias in our code with the following:
Old:
As far as I know you cannot change the Namespace of an imported DLL or NuGet. Usually you want to either use the using like
or use the fully qualified namespace like (you can use CTRL+H for replace all occurrences of
Community
withMyProject.Python.Community
):