Skip to content

Commit

Permalink
Add NuGet Package details to MsBuild project
Browse files Browse the repository at this point in the history
  • Loading branch information
ubhaya committed Jan 18, 2024
1 parent 8e7483a commit 52035c4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,63 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<!-- Nuget Package Details -->
<PropertyGroup>
<version>1.0.0</version>
<title>CleanArchitecture.Blazored.MsBuild</title>
<authors>John</authors>
<description>Generates a strongly typed setting class base on a txt file</description>
<tags>MyTags</tags>
<copyright>Copyright ©Contoso 2022</copyright>

<!-- we need the assemblies bundled, so set this so we don't expose any dependencies to the outside world -->
<GenerateDependencyFile>true</GenerateDependencyFile>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
<!-- This property tells MSBuild where the root folder of the package's build assets should be. Because we are not a library package, we should not pack to 'lib'. Instead, we choose 'tasks' by convention. -->
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
<!-- NuGet does validation that libraries in a package are exposed as dependencies, but we _explicitly_ do not want that behavior for MSBuild tasks. They are isolated by design. Therefore we ignore this specific warning. -->
<NoWarn>NU5100</NoWarn>
<DebugType>embedded</DebugType>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="17.8.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.8.3" PrivateAssets="asll" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="17.8.3" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.8.3" />
<!-- These lines pack the build props/targets files to the `build` folder in the generated package.
By convention, the .NET SDK will look for build\<Package Id>.props and build\<Package Id>.targets
for automatic inclusion in the build. -->
<Content Include="build\CleanArchitecture.Blazored.MsBuild.props" PackagePath="build\" />
<Content Include="build\CleanArchitecture.Blazored.MsBuild.targets" PackagePath="build\" />
</ItemGroup>

<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
<ItemGroup>
<!-- The dependencies of your MSBuild task must be packaged inside the package, they cannot be expressed as normal PackageReferences -->
<BuildOutputInPackage
Include="@(ReferenceCopyLocalPaths)"
TargetPath="%(ReferenceCopyLocalPaths.DestinationSubPath)" />
</ItemGroup>
</Target>

<!-- This target adds the generated deps.json file to our package output -->
<Target Name="AddBuildDependencyFileToBuiltProjectOutputGroupOutput"
BeforeTargets="BuiltProjectOutputGroup"
Condition=" '$(GenerateDependencyFile)' == 'true'">

<ItemGroup>
<BuiltProjectOutputGroupOutput
Include="$(ProjectDepsFilePath)"
TargetPath="$(ProjectDepsFileName)"
FinalOutputPath="$(ProjectDepsFilePath)" />
</ItemGroup>
</Target>

<Target Name="Checking" BeforeTargets="Build">
<Message Importance="high" Text="Filename: $(MSBuildThisFileName)"/>
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--defining properties interesting for my task-->
<PropertyGroup>
<!--The folder where the custom task will be present. It points to inside the NuGet package. -->
<CustomTasksFolder>$(MSBuildThisFileDirectory)..\tasks\net8.0</CustomTasksFolder>
<!--Reference to the assembly which contains the MSBuild Task-->
<CustomTasksAssembly>$(CustomTasksFolder)\$(MSBuildThisFileName).dll</CustomTasksAssembly>
</PropertyGroup>

<!--Register our custom task-->
<!-- <UsingTask TaskName="$(MSBuildThisFileName).$(MSBuildThisFileName)" AssemblyFile="$(CustomTasksAssembly)"/>-->
<UsingTask TaskName="$(MSBuildThisFileName).ReplaceFileText"
AssemblyFile="$(CustomTasksAssembly)"/>
<UsingTask TaskName="$(MSBuildThisFileName).ReplaceFilename"
AssemblyFile="$(CustomTasksAssembly)"/>
<UsingTask TaskName="$(MSBuildThisFileName).GenerateTemplateMarkDownFile"
AssemblyFile="$(CustomTasksAssembly)"/>
<UsingTask TaskName="$(MSBuildThisFileName).GenerateTemplateReadMeFiles"
AssemblyFile="$(CustomTasksAssembly)"/>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

0 comments on commit 52035c4

Please sign in to comment.