Skip to content

Commit 55fc4b2

Browse files
authored
Add support for ImplicitUsings in dotnetbase (#2697)
1 parent c950bf7 commit 55fc4b2

6 files changed

Lines changed: 87 additions & 0 deletions

File tree

modules/vstudio/_preload.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@
158158
default = false
159159
}
160160

161+
p.api.register {
162+
name = "enableimplicitusings",
163+
scope = "config",
164+
kind = "string",
165+
allowed = {
166+
"Default",
167+
"On",
168+
"Off"
169+
}
170+
}
171+
161172
p.api.register {
162173
name = "externalanglebrackets",
163174
scope = "config",

modules/vstudio/tests/cs2005/test_netcore.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,40 @@ function suite.allowUnsafeProperty_core()
138138
]]
139139
end
140140

141+
function suite.implicitUsings_on()
142+
p.action.set("vs2022")
143+
dotnetframework "net10.0"
144+
enableimplicitusings "On"
145+
prepareProjectProperties()
146+
test.capture [[
147+
<PropertyGroup>
148+
<OutputType>Exe</OutputType>
149+
<AppDesignerFolder>Properties</AppDesignerFolder>
150+
<TargetFramework>net10.0</TargetFramework>
151+
<Configurations>Debug;Release;Distribution</Configurations>
152+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
153+
<ImplicitUsings>true</ImplicitUsings>
154+
</PropertyGroup>
155+
]]
156+
end
157+
158+
function suite.implicitUsings_off()
159+
p.action.set("vs2022")
160+
dotnetframework "net10.0"
161+
enableimplicitusings "Off"
162+
prepareProjectProperties()
163+
test.capture [[
164+
<PropertyGroup>
165+
<OutputType>Exe</OutputType>
166+
<AppDesignerFolder>Properties</AppDesignerFolder>
167+
<TargetFramework>net10.0</TargetFramework>
168+
<Configurations>Debug;Release;Distribution</Configurations>
169+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
170+
<ImplicitUsings>false</ImplicitUsings>
171+
</PropertyGroup>
172+
]]
173+
end
174+
141175
function suite.project_element_configurations()
142176
p.action.set("vs2022")
143177
dotnetframework "net8.0"

modules/vstudio/vs2005_csproj.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
dotnetbase.csversion,
5555
dotnetbase.projectConfigurations,
5656
dotnetbase.netcore.enableDefaultCompileItems,
57+
dotnetbase.netcore.enableImplicitUsings,
5758
dotnetbase.netcore.dotnetsdk
5859
}
5960
else

modules/vstudio/vs2005_dotnetbase.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,17 @@
817817
_p(2,'<EnableDefaultCompileItems>%s</EnableDefaultCompileItems>', iif(cfg.enableDefaultCompileItems, "true", "false"))
818818
end
819819

820+
function dotnetbase.netcore.enableImplicitUsings(cfg)
821+
local types = {
822+
Off = "false",
823+
On = "true"
824+
}
825+
826+
if _ACTION >= "vs2022" and dotnetbase.isNewFormatProject(cfg) and types[cfg.enableimplicitusings] then
827+
_p(2,'<ImplicitUsings>%s</ImplicitUsings>', types[cfg.enableimplicitusings])
828+
end
829+
end
830+
820831
function dotnetbase.netcore.useWpf(cfg)
821832
if cfg.wpf == p.ON then
822833
_p(2,'<UseWpf>true</UseWpf>')
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Specifies if C# implicit usings should be enabled. Defaults to `Off`.
2+
3+
```lua
4+
enableimplicitusings ("value")
5+
```
6+
7+
### Parameters ###
8+
9+
`value` is one of:
10+
11+
| Value | Description |
12+
|---------|-------------|
13+
| Default | Don't include property for implicit usings |
14+
| On | Enable C# implicit usings. |
15+
| Off | Disable C# implicit usings. |
16+
17+
## Applies To ###
18+
19+
Project configurations.
20+
21+
### Availability ###
22+
23+
Premake 5.0.0 or later for Visual Studio C# Projects.
24+
25+
### Examples ###
26+
27+
```lua
28+
enableimplicitusings "On"
29+
```

website/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ module.exports = {
134134
'embedandsign',
135135
'enable64bitchecks',
136136
'enabledefaultcompileitems',
137+
'enableimplicitusings',
137138
'enablemodules',
138139
'enablepch',
139140
'enableunitybuild',

0 commit comments

Comments
 (0)