Skip to content

Commit 5724229

Browse files
committed
Add support for ImplicitUsings in dotnetbase
1 parent 2ca338a commit 5724229

7 files changed

Lines changed: 94 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,19 @@
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
827+
dotnetbase.isNewFormatProject(cfg) and
828+
types[cfg.enableImplicitUsings] then
829+
_p(2,'<ImplicitUsings>%s</ImplicitUsings>', types[cfg.enableImplicitUsings])
830+
end
831+
end
832+
820833
function dotnetbase.netcore.useWpf(cfg)
821834
if cfg.wpf == p.ON then
822835
_p(2,'<UseWpf>true</UseWpf>')

tests/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
script_dir=`dirname -- "$0"`
2+
echo $script_dir
3+
pushd "$script_dir"
4+
../bin/debug/premake5 /scripts=.. /file=../premake5.lua "$@" test
5+
popd
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
@@ -133,6 +133,7 @@ module.exports = {
133133
'embedandsign',
134134
'enable64bitchecks',
135135
'enabledefaultcompileitems',
136+
'enableimplicitusings',
136137
'enablemodules',
137138
'enablepch',
138139
'enableunitybuild',

0 commit comments

Comments
 (0)