Skip to content
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

.NET C# no way to enable different .NET sdk's on .netcore projects! #2289

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
34a8b7b
added C# documentationFile feature
Jun 29, 2023
42128d0
wrote unit tests for C# documentationFile
Jun 29, 2023
753b78e
removed null opt to not enable documentationFile
Jun 29, 2023
c74f42f
add documentationFile documentation
Jun 29, 2023
3c168d9
add documentationFile documentation
Jun 29, 2023
6a5bee2
resolve merge confflict with documentation
Jun 29, 2023
3c60b2c
added some extra info for custom dir
Jul 1, 2023
aa6bac0
implemented comments
Jul 4, 2023
faae641
fixed title
Jul 4, 2023
17a9b04
fixed spelling + addd test
Jul 6, 2023
ac1b8cb
fixed spelling + addd test
Jul 6, 2023
652ab29
Merge branch 'master' of https://github.com/lolrobbe2/premake-core
Jul 9, 2023
a228108
improved grammar / capitalization
Aug 30, 2023
fe84d57
changed styling of the documentation
Aug 31, 2023
e831595
changed docs to fit api
Sep 2, 2023
dbd70b5
added MSFT links to See Also
Sep 2, 2023
19715dd
fixed capitalization
Oct 1, 2023
ce31e60
changed wording/ capitalization of documentation
Oct 1, 2023
40167fe
removed the slashes!
Oct 2, 2023
9707d8f
added documenationfile to the sidebar
Oct 5, 2023
3533b2a
Rename documentationFile.md to documentationfile.md
lolrobbe2 Oct 31, 2023
36903cc
merged from master
Jun 9, 2024
f50609c
added support for newer <GenerateDocumentationFile> tag
Jun 9, 2024
912aac2
Merge branch 'master' of https://github.com/premake/premake-core
Sep 27, 2024
44165f5
changed tests
Sep 27, 2024
ef4ac4d
changed default from documentationfile "" to documentationfile(true)
Sep 27, 2024
3ec3b33
changed documentation to match!
Sep 27, 2024
28374f7
changed availability in docs for documentationfile.md
Sep 27, 2024
1946ed0
Merge branch 'master' of https://github.com/premake/premake-core
Oct 7, 2024
d0bd40f
added support to select .NET sdk in visual studio.
Oct 7, 2024
29fe49f
updated sidebar.js
Oct 7, 2024
8cf3ccc
added comma!
Oct 7, 2024
63964d8
use map instead of ugly if else statement.
lolrobbe2 Oct 8, 2024
76b9709
tried to cleanup projectElement function to extract the wpf sdk selec…
Oct 8, 2024
b409321
put the api.register next to dotnetframework register function
Oct 8, 2024
67b90c3
figured out the file logic
Oct 8, 2024
e0a4f80
implemented feedback from samsinsane
Oct 9, 2024
06ce5b6
added a test for WPF flag
Oct 9, 2024
bff0fa9
updated the dotnetsk options in the docs
Oct 9, 2024
3698bec
fixed WindowsDesktop type and added Default to docs
Oct 9, 2024
566a587
implemented feedback from Jarod42
Oct 9, 2024
9fe2531
added test but test is not fully correct because file is not written …
Oct 9, 2024
1a25b9f
at this point when running tests file creation is blocked i think bec…
Oct 9, 2024
d30ae4c
removed the global.json test and put a warning comment in the appropr…
Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions modules/vstudio/_preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"Hull",
"Domain",
"Compute",
"Library",
"Library",
"Mesh",
"Amplification",
"Texture",
Expand Down Expand Up @@ -255,7 +255,7 @@
scope = "config",
kind = "string",
}

-- Relative per-project directory. Set to empty for the entire project to be copied as is
-- Should default to empty really for the more seamless experience
p.api.register {
Expand Down Expand Up @@ -294,6 +294,21 @@
tokens = "true",
}

p.api.register {
name = "dotnetsdk",
scope = "project",
kind = "string",
allowed = {
"Default",
"Web",
"Razor",
"Worker",
"Blazor",
"WindowsDesktop",
"MSTest"
}
}

--
-- Decide when the full module should be loaded.
--
Expand Down
1 change: 1 addition & 0 deletions modules/vstudio/tests/_tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ return {
"cs2005/test_debug_props.lua",
"cs2005/test_debug_props_2019.lua",
"cs2005/test_documentation_file.lua",
"cs2005/test_dotnetsdk.lua",
"cs2005/test_files.lua",
"cs2005/test_icon.lua",
"cs2005/test_netcore.lua",
Expand Down
128 changes: 128 additions & 0 deletions modules/vstudio/tests/cs2005/test_dotnetsdk.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
--
-- tests/actions/vstudio/cs2005/test_dotnetsdk.lua
-- Test DotnetSDK feature Visual Studio 2005+ C# project.
-- Copyright (c) 2012-2024 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("vstudio_cs2005_dotnetsdk")
local dn2005 = p.vstudio.dotnetbase
--
-- Setup
--

local wks, prj, cwd

--
-- Setup and teardown
--
function suite.setup()
cwd = os.getcwd()
os.chdir(_TESTS_DIR)

p.action.set("vs2010")
wks = test.createWorkspace()
configurations { "Debug", "Release" }
language "C#"
dotnetframework "net8.0"
end

function suite.teardown()
os.chdir(cwd)
end
local function setConfig()
local cfg = test.getconfig(prj, "Debug")
dn2005.projectElement(cfg);
end

local function prepare()
prj = test.getproject(wks, 1)
end

function suite.testNone()
prepare()
setConfig()

test.capture [[
<Project Sdk="Microsoft.NET.Sdk">
]]
end

function suite.testDefault()
prepare()
setConfig()
dotnetsdk "Web"
test.capture [[
<Project Sdk="Microsoft.NET.Sdk">
]]
end

function suite.testWeb()
prepare()
dotnetsdk "Web"
setConfig()

test.capture [[
<Project Sdk="Microsoft.NET.Sdk.Web">
]]
end

function suite.testRazor()
prepare()
dotnetsdk "Razor"
setConfig()

test.capture [[
<Project Sdk="Microsoft.NET.Sdk.Razor">
]]
end

function suite.testWorker()
prepare()
dotnetsdk "Worker"
setConfig()

test.capture [[
<Project Sdk="Microsoft.NET.Sdk.Worker">
]]
end

function suite.testBlazor()
prepare()
dotnetsdk "Blazor"
setConfig()

test.capture [[
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
]]
end

function suite.testWindowsDesktop()
prepare()
dotnetsdk "WindowsDesktop"
setConfig()

test.capture [[
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
]]
end

function suite.testMSTest()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global.json part is not tested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would i go about that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue is probably that global.json doesn't follow other file generation and so dotnetbase.netcore.dotnetsdk would be misplaced...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you happen to know where i can find another example of this file generating?

prepare()
dotnetsdk "MSTest"
setConfig()

test.capture [[
<Project Sdk="MSTest.Sdk">
]]
end

function suite.testWPFFlag()
prepare()
dotnetsdk "Web"
flags { "WPF" }
setConfig()

test.capture [[
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
]]
end
1 change: 1 addition & 0 deletions modules/vstudio/vs2005_csproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
dotnetbase.netcore.useWpf,
dotnetbase.csversion,
dotnetbase.netcore.enableDefaultCompileItems,
dotnetbase.netcore.dotnetsdk
}
else
return {
Expand Down
32 changes: 27 additions & 5 deletions modules/vstudio/vs2005_dotnetbase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@

function dotnetbase.projectElement(prj)
if dotnetbase.isNewFormatProject(prj) then
if prj.flags.WPF then
_p('<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">')
else
_p('<Project Sdk="Microsoft.NET.Sdk">')
end
_p('<Project Sdk="%s">', dotnetbase.netcore.getsdk(prj))
else
local ver = ''
local action = p.action.current()
Expand Down Expand Up @@ -820,6 +816,32 @@
end
end

function dotnetbase.netcore.getsdk(cfg)
local map = {
["Default"] = "Microsoft.NET.Sdk",
["Web"] = "Microsoft.NET.Sdk.Web",
["Razor"] = "Microsoft.NET.Sdk.Razor",
["Worker"] = "Microsoft.NET.Sdk.Worker",
["Blazor"] = "Microsoft.NET.Sdk.BlazorWebAssembly",
["WindowsDesktop"] = "Microsoft.NET.Sdk.WindowsDesktop",
["MSTest"] = "MSTest.Sdk",
}

if cfg.flags.WPF then
return map["WindowsDesktop"]
end

return map[cfg.dotnetsdk or "Default"]
end

function dotnetbase.netcore.dotnetsdk(cfg)
-- do not remove the file generation for global.json otherwise MSTest will not work!!!
local globalpath = path.join(cfg.workspace.location, "global.json")
if cfg.dotnetsdk == "MSTest" and not os.isfile(globalpath) then
io.writefile(globalpath, '{"msbuild-sdks": {"MSTest.Sdk": "3.6.1"}}')
end
end

function dotnetbase.allowUnsafeBlocks(cfg)
if cfg.clr == "Unsafe" then
_p(2,'<AllowUnsafeBlocks>true</AllowUnsafeBlocks>')
Expand Down
36 changes: 36 additions & 0 deletions website/docs/dotnetsdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Selects a .NET SDK

```lua
dotnetsdk "SDK"
```

For more information see the MSDN documentation [here](https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview)

## parameters ##
`SDK` is one of:

* [Default](https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props)
* [Web](https://learn.microsoft.com/en-us/aspnet/core/razor-pages/web-sdk?toc=%2Fdotnet%2Fnavigate%2Ftools-diagnostics%2Ftoc.json&bc=%2Fdotnet%2Fbreadcrumb%2Ftoc.json)
* [Razor](https://learn.microsoft.com/en-us/aspnet/core/razor-pages/sdk?toc=%2Fdotnet%2Fnavigate%2Ftools-diagnostics%2Ftoc.json&bc=%2Fdotnet%2Fbreadcrumb%2Ftoc.json)
* [Worker](https://learn.microsoft.com/en-us/dotnet/core/extensions/workers)
* [Blazor](https://learn.microsoft.com/en-us/aspnet/core/blazor/)
* [WindowsDesktop](https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props-desktop?view=aspnetcore-8.0)
* [MSTest](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-mstest-sdk)


## mstest ##
SDK used for MSTest is `"3.6.1"`, to use another version create or update global.json near the solution.
### Applies To ###

Project configurations.

### Availability ###

Premake 5.0 beta3 or later.

Visual studio is the only toolset currently supported.

### Examples ###
```lua
dotnetsdk "Web"
```
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ module.exports = {
'docname',
'documentationfile',
'dotnetframework',
'dotnetsdk',
'dpiawareness',
'editandcontinue',
'editorintegration',
Expand Down