C
C#5mo ago
Anton

MSBuild make it NOT copy a dependency to the output path

<!-- Make sure the CLI has been built before calling into it -->
<ItemGroup Condition="'$(IsTools)' != 'True'">
<ProjectReference Include="$(RootDirectory)tools\Cli\Cli.csproj">
<IncludeAssets>none</IncludeAssets>
<ExcludeAssets>all</ExcludeAssets>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<!-- Make sure the CLI has been built before calling into it -->
<ItemGroup Condition="'$(IsTools)' != 'True'">
<ProjectReference Include="$(RootDirectory)tools\Cli\Cli.csproj">
<IncludeAssets>none</IncludeAssets>
<ExcludeAssets>all</ExcludeAssets>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
How in the world does this still end up copying everything but the dll? It copies the exe and runtimeconfig and deps jsons, whatever those are. I'm not going to be calling it at runtime.
3 Replies
dreadfullydistinct
I’m not recommending this but I wrote this for a cli tool I wanted to run automatically on build (not sure if you’re doing the same)
<Target Name="MissionDesigner" BeforeTargets="MasterAssetConverter" Inputs="@(MissionProgressionInfoCs)" Outputs="$(MasterAssetResources)/Missions/MissionProgressionInfo.json">
<MSBuild Projects="../DragaliaAPI.MissionDesigner/DragaliaAPI.MissionDesigner.csproj">
<Output ItemName="DesignerOutputs" TaskParameter="TargetOutputs" />
</MSBuild>

<PropertyGroup>
<MissionDesignerDll>%(DesignerOutputs.Identity)</MissionDesignerDll>
</PropertyGroup>

<Exec Command="dotnet $(MissionDesignerDll) $(MasterAssetResources)" ConsoleToMSBuild="true" />
</Target>
<Target Name="MissionDesigner" BeforeTargets="MasterAssetConverter" Inputs="@(MissionProgressionInfoCs)" Outputs="$(MasterAssetResources)/Missions/MissionProgressionInfo.json">
<MSBuild Projects="../DragaliaAPI.MissionDesigner/DragaliaAPI.MissionDesigner.csproj">
<Output ItemName="DesignerOutputs" TaskParameter="TargetOutputs" />
</MSBuild>

<PropertyGroup>
<MissionDesignerDll>%(DesignerOutputs.Identity)</MissionDesignerDll>
</PropertyGroup>

<Exec Command="dotnet $(MissionDesignerDll) $(MasterAssetResources)" ConsoleToMSBuild="true" />
</Target>
I am almost certain there is a better way to do it, but that basically doesn’t add the reference or do any copying but just sort of runs it in its own directory as I would manually The inputs of the cs files is what triggers a rebuild, with the notable disadvantage that non code changes like csproj will not Anyway, hopefully cunninghams law kicks in and someone comes in to tell us how to do it 😄
Anton
AntonOP5mo ago
well your solution is basically equivalent to calling dotnet run I've tried it with just dotnet run to let it build by itself - that's kinda slow, it checking to see if it's built or not, adds half a second to every project that runs it - they sometimes end up running it simultaneously, idk how honestly, but that breaks the build so I'm doing dotnet run --conriguration=$(Configuration) (or else it won't work for release) --no-build (can do this safely thanks to the project reference) that just so that I don't have to hardcode the path the annoying thing is that the cli has to run in the same mode that the project is same configuration if you hardcode Release for the cli project, builds break, because it still references the same configuration as itself
dreadfullydistinct
I think there is some subtle difference in that using the msbuild task will schedule it as part of the current compilation and won’t have the parallelism problems. That’s what I observed after switching to that from dotnet run anyway But yes it’s probably slower than a project reference I didn’t know about ReferenceOutputAssembly=false, maybe that’s the way
Want results from more Discord servers?
Add your server