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 36 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
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
101 changes: 101 additions & 0 deletions modules/vstudio/tests/cs2005/test_dotnetsdk.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
--
-- tests/actions/vstudio/cs2005/test_dotnetsdk.lua
-- Test DocumentationFile feature Visual Studio 2005+ C# project.
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved
-- 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

--
-- Setup and teardown
--
function suite.setup()
p.action.set("vs2010")
wks = test.createWorkspace()
configurations { "Debug", "Release" }
language "C#"
dotnetframework "net8.0"
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.testDefault()
prepare()
setConfig()

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()
prepare()
dotnetsdk "mstest"
setConfig()

test.capture [[
<Project Sdk="MSTest.Sdk">
]]
end
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved
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
30 changes: 25 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,30 @@
end
end

function dotnetbase.netcore.getsdk(cfg)
if cfg.flags.WP then
return nmap["windowsdesktop"]
elseif not cfg.dotnetsdk then
return "Microsoft.NET.Sdk"
end
local map = {
["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",
}
return map[cfg.dotnetsdk]
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved
end

function dotnetbase.netcore.dotnetsdk(cfg)
globalpath = string.format("%s/global.json",cfg.workspace.location)
if cfg.dotnetsdk == "mstest" and not os.isfile(globalpath) then
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved
io.writefile(globalpath,"{\"msbuild-sdks\": {\"MSTest.Sdk\": \"3.6.1\"}}")
end
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved
end

function dotnetbase.allowUnsafeBlocks(cfg)
if cfg.clr == "Unsafe" then
_p(2,'<AllowUnsafeBlocks>true</AllowUnsafeBlocks>')
Expand Down
14 changes: 14 additions & 0 deletions src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,20 @@
kind = "string",
}

api.register {
name = "dotnetsdk",
scope = "project",
kind = "string",
allowed = {
"web",
"razor",
"worker",
"blazor",
"windowsdesktop",
"mstest"
}
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved
}

api.register {
name = "enabledefaultcompileitems",
scope = "config",
Expand Down
47 changes: 47 additions & 0 deletions website/docs/dotnetsdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Selects a .NET Sdk
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved

```lua
dotnetsdk "sdk"
```

[overview](https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview)
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved

## parameters ##
`sdk` is one of
Copy link
Member

Choose a reason for hiding this comment

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

This line should end with a colon and should have an empty line after it before the starting the list.

* [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 ##
to make the MSTest sdk work you need to add the version to `global.json`:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to generate that file too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes i was thinking about that but how would i make it so you could specify the version? or do i just have a default version and tell people where they can change it! and code for writing the file as i am not familliar with the file api's of premake

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it is adapted but something like MSTest-3.6.1 might be an option
if version are limited, you might hard-code them, else extract version after '-' is also possible.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
to make the MSTest sdk work you need to add the version to `global.json`:
To make the MSTest SDK work you need to add the version to `global.json`:

Also, according to this you don't need to use global.json, you can have the version in the .csproj with the SDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes that is correct but specifiying it becomes a little hard so i decided on the global.json route

```json
{
"msbuild-sdks": {
"MSTest.Sdk": "3.6.1"
}
}
```
:::warning
`global.json` needs to be located in the same folder as your solution
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`global.json` needs to be located in the same folder as your solution
`global.json` needs to be located in the same folder as your solution.

:::

### Applies To ###

Project configurations.

### Availability ###

Premake 5.0 beta3 or later.

Visual studio is the only toolset currently supported.

### Examples ###
use the web sdk
Copy link
Member

Choose a reason for hiding this comment

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

This description is unnecessary, the example is self-documenting.


```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