Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
95 changes: 32 additions & 63 deletions Content/Library/build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,39 @@ let deleteChangelogBackupFile _ =
if String.isNotNullOrEmpty Changelog.changelogBackupFilename then
Shell.rm Changelog.changelogBackupFilename

let assemblyInfoMsBuildArgs () =
let releaseChannel =
match latestEntry.SemVer.PreRelease with
| Some pr -> pr.Name
| _ -> "release"

let releaseDate = latestEntry.Date.Value.ToString("o")

let gitHash =
try
Git.Information.getCurrentSHA1 (null)
with _ ->
""

[
$"/p:Version={latestEntry.AssemblyVersion}"
$"/p:AssemblyVersion={latestEntry.AssemblyVersion}"
$"/p:FileVersion={latestEntry.AssemblyVersion}"
$"/p:InformationalVersion={latestEntry.AssemblyVersion}"
$"/p:AssemblyMetadataReleaseDate={releaseDate}"
$"/p:AssemblyMetadataReleaseChannel={releaseChannel}"
$"/p:AssemblyMetadataGitHash={gitHash}"
]


let dotnetBuild ctx =
let isDotnetPack = ctx.Context.TryFindTarget("DotnetPack").IsSome

let args = [
sprintf "/p:PackageVersion=%s" latestEntry.NuGetVersion
"--no-restore"
if isDotnetPack then
yield! assemblyInfoMsBuildArgs ()
Comment thread
TheAngryByrd marked this conversation as resolved.
Outdated
]

DotNet.build
Expand Down Expand Up @@ -510,68 +538,18 @@ let watchTests _ =
cancelEvent.Cancel <- true

let generateAssemblyInfo _ =
let isNoop = true

let (|Fsproj|Csproj|Vbproj|) (projFileName: string) =
match projFileName with
| f when f.EndsWith("fsproj") -> Fsproj
| f when f.EndsWith("csproj") -> Csproj
| f when f.EndsWith("vbproj") -> Vbproj
| _ ->
failwith (sprintf "Project file %s not supported. Unknown project type." projFileName)

let releaseChannel =
match latestEntry.SemVer.PreRelease with
| Some pr -> pr.Name
| _ -> "release"

let getAssemblyInfoAttributes projectName = [
AssemblyInfo.Title(projectName)
AssemblyInfo.Product productName
AssemblyInfo.Version latestEntry.AssemblyVersion
AssemblyInfo.Metadata("ReleaseDate", latestEntry.Date.Value.ToString("o"))
AssemblyInfo.FileVersion latestEntry.AssemblyVersion
AssemblyInfo.InformationalVersion latestEntry.AssemblyVersion
AssemblyInfo.Metadata("ReleaseChannel", releaseChannel)
AssemblyInfo.Metadata("GitHash", Git.Information.getCurrentSHA1 (null))
]

let getProjectDetails (projectPath: string) =
let projectName = IO.Path.GetFileNameWithoutExtension(projectPath)

(projectPath,
projectName,
IO.Path.GetDirectoryName(projectPath),
(getAssemblyInfoAttributes projectName))

!!srcGlob
|> Seq.map getProjectDetails
|> Seq.iter (fun (projFileName, _, folderName, attributes) ->
match projFileName with
| Fsproj ->
AssemblyInfoFile.createFSharp
(folderName
</> "AssemblyInfo.fs")
attributes
| Csproj ->
AssemblyInfoFile.createCSharp
((folderName
</> "Properties")
</> "AssemblyInfo.cs")
attributes
| Vbproj ->
AssemblyInfoFile.createVisualBasic
((folderName
</> "My Project")
</> "AssemblyInfo.vb")
attributes
)
if isNoop then
()
Comment thread
TheAngryByrd marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot This should just be deleted. What are you even doing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in c6c3c1a. I deleted the no-op GenerateAssemblyInfo target and removed its dependency wiring from Content/Library/build/build.fs, plus removed the stale GenerateAssemblyInfo target entry from Content/Library/README.md. No UI changes in this PR.


let dotnetPack ctx =
// Get release notes with properly-linked version number
let releaseNotes = Changelog.mkReleaseNotes changelog latestEntry gitHubRepoUrl

let args = [
$"/p:PackageVersion={latestEntry.NuGetVersion}"
yield! assemblyInfoMsBuildArgs ()
$"/p:PackageReleaseNotes=\"{releaseNotes}\""
]

Expand Down Expand Up @@ -620,15 +598,6 @@ let gitRelease _ =
Git.Staging.stageFile "" "CHANGELOG.md"
|> ignore

!!(rootDirectory
</> "src/**/AssemblyInfo.fs")
++ (rootDirectory
</> "tests/**/AssemblyInfo.fs")
|> Seq.iter (
Git.Staging.stageFile ""
>> ignore
)

let msg =
sprintf "Bump version to %s\n\n%s" latestEntry.NuGetVersion releaseNotesGitCommitFormat

Expand Down
2 changes: 2 additions & 0 deletions Content/Library/src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Product>MyLib.1</Product>
Comment thread
TheAngryByrd marked this conversation as resolved.
Outdated
<!-- Tell dotnet that anything under src should be packable -->
<IsPackable>true</IsPackable>
<!-- Tell dotnet that anything under src is not a test project -->
Expand Down
10 changes: 8 additions & 2 deletions Content/Library/src/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<Project>
<PropertyGroup>
<PropertyGroup>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
<FSharpAnalyzersOtherFlags>--analyzers-path "$(PkgG-Research_FSharp_Analyzers)/analyzers/dotnet/fs"</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --analyzers-path "$(PkgIonide_Analyzers)/analyzers/dotnet/fs"</FSharpAnalyzersOtherFlags>
</PropertyGroup>
</Project>

<ItemGroup Condition="'$(IsPacking)' == 'true'">
Comment thread
TheAngryByrd marked this conversation as resolved.
Outdated
<AssemblyMetadata Include="ReleaseDate" Value="$(AssemblyMetadataReleaseDate)" Condition="'$(AssemblyMetadataReleaseDate)' != ''" />
<AssemblyMetadata Include="ReleaseChannel" Value="$(AssemblyMetadataReleaseChannel)" Condition="'$(AssemblyMetadataReleaseChannel)' != ''" />
<AssemblyMetadata Include="GitHash" Value="$(AssemblyMetadataGitHash)" Condition="'$(AssemblyMetadataGitHash)' != ''" />
</ItemGroup>
</Project>
23 changes: 0 additions & 23 deletions Content/Library/src/MyLib.1/AssemblyInfo.fs

This file was deleted.

1 change: 0 additions & 1 deletion Content/Library/src/MyLib.1/MyLib.1.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Library.fs" />
</ItemGroup>
</Project>
79 changes: 79 additions & 0 deletions tests/MiniScaffold.Tests/Asserts.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace MiniScaffold.Tests

open System.IO
open System.Diagnostics
open System.Reflection
open System.Runtime.Loader
open Expecto
open Infrastructure
open Fake.IO.FileSystemOperators
Expand Down Expand Up @@ -134,6 +137,82 @@ module Assert =

let ``File exists`` path = tryFindFile path

let ``File does not exist`` file (d: DirectoryInfo) =
let filepath = Path.Combine(d.FullName, file)
Expect.isFalse (File.Exists filepath) (sprintf "%s should not exist" filepath)

let ``assembly info values are set after pack`` projectName (d: DirectoryInfo) =
let dllPath =
Path.Combine(
d.FullName,
"src",
projectName,
"bin",
"Debug",
"net8.0",
$"{projectName}.dll"
)
Comment thread
TheAngryByrd marked this conversation as resolved.
Outdated

Expect.isTrue (File.Exists dllPath) (sprintf "%s should exist" dllPath)

let assemblyName = AssemblyName.GetAssemblyName(dllPath)
Expect.equal assemblyName.Version (Version "0.1.0.0") "AssemblyVersion should be 0.1.0.0"

let fileVersionInfo = FileVersionInfo.GetVersionInfo(dllPath)

Expect.equal fileVersionInfo.FileVersion "0.1.0" "FileVersion should be 0.1.0"

let assemblyContext =
new AssemblyLoadContext($"metadata-{projectName}-{Guid.NewGuid():N}", true)

let assembly = assemblyContext.LoadFromAssemblyPath(dllPath)

let title =
assembly.GetCustomAttribute<AssemblyTitleAttribute>()
|> Option.ofObj
|> Option.map _.Title

Expect.equal title (Some projectName) "AssemblyTitle should match project name"

let product =
assembly.GetCustomAttribute<AssemblyProductAttribute>()
|> Option.ofObj
|> Option.map _.Product

Expect.equal product (Some projectName) "AssemblyProduct should match project name"

let informationalVersion =
assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
|> Option.ofObj
|> Option.map _.InformationalVersion

Expect.equal informationalVersion (Some "0.1.0") "InformationalVersion should be 0.1.0"

let metadata =
assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
|> Seq.map (fun x -> x.Key, x.Value)
|> Map.ofSeq

Expect.equal
(metadata
|> Map.tryFind "ReleaseChannel")
(Some "release")
"ReleaseChannel should be release"

let releaseDate =
metadata
|> Map.tryFind "ReleaseDate"

Expect.isTrue
(releaseDate
|> Option.exists (
String.IsNullOrWhiteSpace
>> not
))
"ReleaseDate should be set"

assemblyContext.Unload()

Comment thread
TheAngryByrd marked this conversation as resolved.
Outdated
module Effect =
open System
open Fake.IO
Expand Down
2 changes: 2 additions & 0 deletions tests/MiniScaffold.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ module Tests =
"-n MyCoolLib --githubUsername CoolPersonNo2",
[
yield! projectStructureAsserts
Assert.``File does not exist`` "src/MyCoolLib/AssemblyInfo.fs"
Assert.``project can build target`` "DotnetPack"
Assert.``assembly info values are set after pack`` "MyCoolLib"
Assert.``project can build target`` "BuildDocs"
]

Expand Down