- generate documentation
- copy to output folder
- csharp macro define csproj
- platform macro
- exclude files from compile
- disable warnings
- force bin,obj clean
- execute cmd before build
- link source from other project
- prebuild copy files
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
</Project>
to disable warn about missing doc
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<noWarn>1591</noWarn>
</PropertyGroup>
</Project>
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<None Include="doc/file.dxf" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
- to be recursive ( sparse files in output )
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<None Include="doc/**/*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
- to be recursive ( single folder in output )
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<None Include="doc/**/*" CopyToOutputDirectory="PreserveNewest" Link="doc/%(RecursiveDir)/%(Filename)%(Extension)" />
</ItemGroup>
- to include in aspnet core publish
<ItemGroup>
<Content Include="somefld/subfld/**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
to define a constant to use in the code like this
#if MYCONST
//
#else
//
#endif
edit .csproj
like follow ( separate by semicolon )
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DefineConstants>MYCONST;MYCONST2</DefineConstants>
</PropertyGroup>
</Project>
or conditionally based on configuration used dotnet build -c Release
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DefineConstants>MYCONST;MYCONST2</DefineConstants>
</PropertyGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
<DefineConstants>WINDOWS_PLATFORM</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
<DefineConstants>OSX_PLATFORM</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
<DefineConstants>LINUX_PLATFORM</DefineConstants>
</PropertyGroup>
</Project>
the use in code like follow
#if WINDOWS_PLATFORM
//
#else
//
#endif
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>server_lib</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Program.cs"/>
</ItemGroup>
</Project>
follow to disable missing XML comment
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<noWarn>1591</noWarn>
</PropertyGroup>
</Project>
bin
and obj
folders recursively starting from current working dir
find -type d -name "bin" -exec rm -fr '{}' \; ; find -type d -name "obj" -exec rm -fr '{}' \;
<Target Name="MyPreBuildTarget" BeforeTargets="Build">
<Exec Command="echo sample"/>
</Target>
<ItemGroup>
<Compile Include="../iot-gateway-api/IOTGateway.cs"/>
</ItemGroup>
follow task will copy a file placed ( relative to csproj ) ../../src/gui/Assets/Dictionary1.xaml
into the csproj folder base relative Assets/gui
before each build
<Target Name="CopyGUIAssets" BeforeTargets="Build">
<Copy SourceFiles="../../src/gui/Assets/Dictionary1.xaml" DestinationFolder="Assets/gui" />
</Target>