-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
ImplicitUsings
is not handled
#436
Comments
I'm not sure how this list is generated so It's hard to tell if it would be worth the maintenance cost to add this feature to rules_dotnet. This can be worked around by the end user by using a bazel macro around the If you have any further information on how this list is generated then that would help with making the decision. |
I actually looked into it a little bit. The way it works is as follows:
https://github.com/dotnet/sdk/blob/f48021c3202146e8ba6c8364fc619b31bef84d89/src/Tasks/Microsoft.NET.Build.Tasks/GenerateGlobalUsings.cs#L8 I might be incorrect, but from what I can understand, the only "proper" ways to get these
|
I've just hit this too, my build is failing. I'm not quite sure what to do. |
@peakschris You wrap the rules with your own macro where you provide a source file with the global imports. But I think I would also accept an contribution that adds the global imports in a maintainable way. |
What I did at work for now:
(Make sure to add |
Want this feature to simplify the migration. Almost all of my projects used this feature. |
It works fine to create an extra .GlobalUsings.g.cs file and add to the project that contains the using statements. This can be added explicitly or in a wrapped rule: MyLibrary.GlobalUsings.g.cs:
But it would be far better if this file was auto-generated in the same way that msbuild does. |
I know this issue is a little old, but the team I work with implemented support for this as suggested by @purkhusid - we intend to contribute it, but it needs some tidying to make it more generally manageable. In particular, we want to provide a better way to manage the namespaces across multiple SDKs and framework versions. However it isn't super complicated to implement, so an outline for what we did might be helpful:
We also added an attribute to allow other global usings to be supplied (like the The code for the genrule isn't especially complex either: def _create_global_usings_file(filename, namespaces):
content = "\n".join(["global using global::%s;" % ns for ns in namespaces])
native.genrule(
name = filename.replace(".cs", ""),
outs = [filename],
cmd = "echo '" + content + "' > $@",
) |
Since
rules_dotnet
doesn't run MSBuild, theUsing
directives added by the Task files in the .NET SDK are not handled, causing the build to fail unless the auto-generated{Assembly}.GlobalUsings.g.cs
is included insrcs
.For the time being, I'm hand-maintaining the following file:
But obviously this isn't very nice. Would there be anyway to generate this file through Bazel somehow?
The text was updated successfully, but these errors were encountered: