Skip to content

Commit d74b05d

Browse files
Merge pull request #41 from wherget/non-core-msbuild
Don't run NetcodePatchTask in non-Core MSBuild.
2 parents 3a46743 + 5ea832c commit d74b05d

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

NetcodePatcher.MSBuild/Sdk/Sdk.targets

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
ReferenceAssemblyPaths="@(ReferencePathWithRefAssemblies)"
99
NoOverwrite="$(NetcodePatcherNoOverwrite)"
1010
DisableParallel="$(NetcodePatcherDisableParallel)"
11+
Condition=" '$(MSBuildRuntimeType)' == 'Core' "
12+
/>
13+
<Warning
14+
Condition=" '$(MSBuildRuntimeType)' != 'Core' "
15+
Code="NCP0001"
16+
Text="The NetcodePatcher MSBuild SDK cannot be used in a .NET Framework MSBuild (e.g. Visual Studio).
17+
You may ignore this warning if you have set up patching using the command line tool.
18+
See the Help Link for details."
19+
HelpLink="https://github.com/EvaisaDev/UnityNetcodePatcher#msbuild"
1120
/>
1221
</Target>
1322

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ Run `netcode-patch --help` for usage information and available options.
6464
### MSBuild
6565

6666
> [!IMPORTANT]
67-
> Due to issues with Visual Studio the MSBuild plugin is not currently working properly with it, using the CLI tool and post build event is recommended if you are using Visual Studio.
67+
> Since Visual Studio still uses 'full' MSBuild (which is based on .NET Framework), some dependencies targeting .NET Standard 2.1
68+
> cannot be loaded into the build host process.
69+
> Using the CLI tool and post build event is recommended if you are using Visual Studio.
70+
> You can use both the SDK and CLI tool depending on your build environemnt. See the example under "Usage with Visual Studio" below.
6871
> *Alternatively you can manually run `dotnet build` from commandline if you do want to use MSBuild.*
6972
7073
NetcodePatcher has an MSBuild plugin that can be applied with minimal configuration.
@@ -101,6 +104,30 @@ to automatically netcode patch the project's output assemblies.
101104

102105
</details>
103106

107+
<details>
108+
<summary>Usage with Visual Studio</summary>
109+
110+
If you want to support building in both environments (e.g. Visual Studio and `dotnet`) you can use CLI tool for Visual Studio builds, with a `Condition="'$(MSBuildRuntimeType)' != 'Core'"`.
111+
112+
```xml
113+
<Project>
114+
<ItemGroup>
115+
<!-- will be automatically skipped for Visual Studio -->
116+
<NetcodePatch Include="$(TargetPath)" />
117+
</ItemGroup>
118+
<PropertyGroup>
119+
<!-- silence the warning message that should have led you to this documentation -->
120+
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NCP0001</MSBuildWarningsAsMessages>
121+
</PropertyGroup>
122+
<Target Name="LegacyNetcodePatch" AfterTargets="NetcodePatch" Condition="'$(MSBuildRuntimeType)' != 'Core'">
123+
<!-- run the CLI patcher only for MSBuilds that cannot load the dependencies -->
124+
<Exec Command="netcode-patch -nv 1.5.2 &quot;$(TargetPath)&quot; @(ReferencePathWithRefAssemblies->'&quot;%(Identity)&quot;', ' ')"/>
125+
</Target>
126+
</Project>
127+
```
128+
129+
</details>
130+
104131
### Manual
105132

106133
1. Download the latest [release](https://github.com/EvaisaDev/UnityNetcodePatcher/releases) asset for your platform.

0 commit comments

Comments
 (0)