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

add C# documentationFile feature #2103

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
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 @@ -13,6 +13,7 @@ return {
"cs2005/test_no_warn.lua",
"cs2005/test_debug_props.lua",
"cs2005/test_debug_props_2019.lua",
"cs2005/test_documentation_file.lua",
"cs2005/test_files.lua",
"cs2005/test_icon.lua",
"cs2005/test_netcore.lua",
Expand Down
72 changes: 72 additions & 0 deletions modules/vstudio/tests/cs2005/test_documentation_file.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
--
-- tests/actions/vstudio/cs2005/test_documentation_file.lua
-- Test DocumentationFile feature Visual Studio 2005+ C# project.
-- Copyright (c) 2012-2023 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("vstudio_cs2005_documentation_file")
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#"
targetdir("test\\targetDir")
end

local function setConfig()
local cfg = test.getconfig(prj, "Debug")
dn2005.documentationfile(cfg);
end



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

local function prepareEmpty()
prepare()
documentationfile ""
setConfig()
end

local function prepareDir()
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved
prepare()
documentationfile "test"
setConfig()
end

local function prepareNull()
p.action.set("vs2010")
wks = test.createWorkspace()
setConfig()
end

function suite.documentationFilePath()
prepareDir()
test.capture [[
<DocumentationFile>test\MyProject.xml</DocumentationFile>
]]
end

function suite.documentationEmpty()
prepareEmpty()
test.capture [[
<DocumentationFile>test\targetDir\MyProject.xml</DocumentationFile>
]]
end

function suite.documentationNull()
prepareNull()
test.isemptycapture()
end
3 changes: 2 additions & 1 deletion modules/vstudio/vs2005_csproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
dotnetbase.debugProps,
dotnetbase.outputProps,
dotnetbase.compilerProps,
dotnetbase.NoWarn
dotnetbase.NoWarn,
dotnetbase.documentationFile,
}
end

Expand Down
11 changes: 9 additions & 2 deletions modules/vstudio/vs2005_dotnetbase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
if dotnetbase.isNewFormatProject(prj) then
if prj.flags.WPF then
_p('<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">')
else
else
_p('<Project Sdk="Microsoft.NET.Sdk">')
end
else
Expand Down Expand Up @@ -754,6 +754,13 @@
end
end

function dotnetbase.documentationfile(cfg)
if cfg.documentationFile then
local documentationFile = iif(cfg.documentationFile ~= "", cfg.documentationFile, cfg.targetdir)
_p(2, string.format('<DocumentationFile>%s\\%s.xml</DocumentationFile>', vstudio.path(cfg, documentationFile),cfg.project.name))
end
end

function dotnetbase.isNewFormatProject(cfg)
local framework = cfg.dotnetframework
if not framework then
Expand Down Expand Up @@ -789,4 +796,4 @@
if cfg.clr == "Unsafe" then
_p(2,'<AllowUnsafeBlocks>true</AllowUnsafeBlocks>')
end
end
end
6 changes: 6 additions & 0 deletions src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,12 @@
}
}

api.register {
name = "documentationfile",
scope = "project",
kind = "string",
}

api.register {
name = "cdialect",
scope = "config",
Expand Down
43 changes: 43 additions & 0 deletions website/docs/documentationFile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved
title: documentationfile
---

Enable C# xmlDocumentationFile
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved

# Usage (2) #
the DocumentationFile is used for adding the [xml comments](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/) added to functions/ variables, to a dll that has been packed inside a framework or other C# related.
this can then be referenced inside another project by placing it next to the corresponding dll.

this feature sets the [DocumentationFile](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/output#documentationfile) option inside csproj for each corresponding [configuration](https://premake.github.io/docs/configurations/)

## 1) Default ##

when you put documentationfile inside the project, the following filename/path will be generated:
```%{targetdir}/%{prj.name}.xml```
```lua
documentationfile ""
```

## 2) Custom Directory ##

when you put the following inside the project the following filename/path will be generated:
lolrobbe2 marked this conversation as resolved.
Show resolved Hide resolved
```bin\test\%{prj.name}.xml```

```lua
documentationfile "bin/test"
```
<b>the path is relative to the project [location](https://premake.github.io/docs/location/)

### Applies To ###

The `project` scope.

### Availability ###

Visual Studio 2005

## <b>NOTE !</b> ##
it is recommended to use the default option because Visual Studio can only apply the DocumentationFile when it is placed directly next to the corresponding dll.

## See Also ##
more [info](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/#create-xml-documentation-output)
Loading