Skip to content

Commit

Permalink
Improve support of WPF projects
Browse files Browse the repository at this point in the history
Workaround for #404 till the dependent bugs we have open against NuGet are resolved.

This workaround is only complete with two xml snippets added to a WPF project:

Add this just under the opening `<Project>` tag:

```xml
  <Import Project="$(BaseIntermediateOutputPath)$(_TargetAssemblyProjectName)$(MSBuildProjectExtension).nuget.g.props"
          Condition=" '$(_TargetAssemblyProjectName)' != '' and '$(ImportProjectExtensionProps)' != 'false' and exists('$(BaseIntermediateOutputPath)$(_TargetAssemblyProjectName)$(MSBuildProjectExtension).nuget.g.props')" />
```

Add this just above the closing `</Project>` tag:

```xml
  <Import Project="$(BaseIntermediateOutputPath)$(_TargetAssemblyProjectName)$(MSBuildProjectExtension).nuget.g.targets"
          Condition=" '$(_TargetAssemblyProjectName)' != '' and '$(ImportProjectExtensionProps)' != 'false' and exists('$(BaseIntermediateOutputPath)$(_TargetAssemblyProjectName)$(MSBuildProjectExtension).nuget.g.targets')" />
```

This is tested to work both for .NET Framework WPF projects and .NET Core WPF projects.
  • Loading branch information
AArnott committed Nov 15, 2019
1 parent 2b0c747 commit 8ea2e5d
Showing 1 changed file with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="NBGV_SetDefaults">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>

<PrepareForBuildDependsOn>
GenerateNativeVersionInfo;
$(PrepareForBuildDependsOn);
</PrepareForBuildDependsOn>

<PrepareResourcesDependsOn>
GenerateAssemblyVersionInfo;
$(PrepareResourcesDependsOn)
</PrepareResourcesDependsOn>

<CoreCompileDependsOn>
GenerateAssemblyVersionInfo;
$(CoreCompileDependsOn)
</CoreCompileDependsOn>

<VersionDependsOn>
GetNuPkgVersion;
$(VersionDependsOn)
Expand All @@ -33,9 +18,6 @@
$(GetPackageVersionDependsOn)
</GetPackageVersionDependsOn>

<!-- Suppress assembly version info generation if not obviously compiling an assembly. -->
<GenerateAssemblyVersionInfo Condition=" '$(GenerateAssemblyVersionInfo)' == '' and '$(TargetExt)' != '.dll' and '$(TargetExt)' != '.exe'">false</GenerateAssemblyVersionInfo>

<!-- Suppress version attribute generation in Microsoft.NET.Sdk projects to avoid build failures
when two sets of attributes are emitted. -->
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
Expand All @@ -53,6 +35,32 @@
<UsingTask AssemblyFile="$(NerdbankGitVersioningTasksPath)Nerdbank.GitVersioning.Tasks.dll" TaskName="Nerdbank.GitVersioning.Tasks.GetBuildVersion"/>
<UsingTask AssemblyFile="$(NerdbankGitVersioningTasksPath)Nerdbank.GitVersioning.Tasks.dll" TaskName="Nerdbank.GitVersioning.Tasks.CompareFiles"/>

<Target Name="NBGV_SetDefaults">
<!-- Workarounds for https://github.com/AArnott/Nerdbank.GitVersioning/issues/404 -->
<PropertyGroup>
<!-- $(TargetExt) isn't set at evaluation time for us when built in wpftmp.csproj with manual imports -->
<!-- Suppress assembly version info generation if not obviously compiling an assembly. -->
<GenerateAssemblyVersionInfo Condition=" '$(GenerateAssemblyVersionInfo)' == '' and '$(TargetExt)' != '.dll' and '$(TargetExt)' != '.exe'">false</GenerateAssemblyVersionInfo>

<!-- Workaround the property stomping that msbuild does (see https://github.com/microsoft/msbuild/pull/4922) with manual imports. -->
<PrepareForBuildDependsOn>
GenerateNativeVersionInfo;
$(PrepareForBuildDependsOn);
</PrepareForBuildDependsOn>

<PrepareResourcesDependsOn>
GenerateAssemblyVersionInfo;
$(PrepareResourcesDependsOn)
</PrepareResourcesDependsOn>

<CoreCompileDependsOn>
GenerateAssemblyVersionInfo;
$(CoreCompileDependsOn)
</CoreCompileDependsOn>

</PropertyGroup>
</Target>

<PropertyGroup>
<!-- Consider building a tag to be more precise than the branch we're building. -->
<_NBGV_BuildingRef>$(_NBGV_BuildingTag)</_NBGV_BuildingRef>
Expand Down

0 comments on commit 8ea2e5d

Please sign in to comment.