0

I have solution with about 50 projects. The projects have 2 target frameworks: netcore1.1 and .net 4.6. All the projects are based on xproj.

So as build result I have binaries in bin/$configuration/$targetfw/. F.ex. in my case I have binaries in bin/debug/netcoreapp and bin/debug/net462 outputs.

But I need to have copy of bin/debug/net462 content in /bin directory too.

How to make it correctly by script in project.json or smth else for all 50 projcts of solution? And it would be great if fix wont be visible for git source control.

P.s. Why i need it? Because VS code map tool looks for binaries in bin directly

UPD.

<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
  <PropertyGroup Label="Globals">
    <ProjectGuid>9e2d06cb-21aa-4457-ab44-6e67298037e3</ProjectGuid>
    <RootNamespace>SmartDoc.Domain.Document</RootNamespace>
    <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
    <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>
  <PropertyGroup>
    <SchemaVersion>2.0</SchemaVersion>
  </PropertyGroup>
  <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
vitm
  • 473
  • 1
  • 3
  • 12

1 Answers1

1

How to make it correctly by script in project.json or smth else for all 50 projcts of solution? And it would be great if fix wont be visible for git source control.

You can add a custom MSBuild task to copy the binaries from bin/$configuration/$targetfw/ to /bin directory.

To accomplish this, unload your project, edit it, add following code before ending tag </Project>:

  <ItemGroup>
    <MySourceFiles Include="$(ProjectDir)bin\$(Configuration)\**\$(ProjectName).dll"/>
  </ItemGroup>


  <Target Name="TestCopy" AfterTargets="Build">

    <Message Text ="Copy file to bin folder." Importance="high"></Message>

    <Copy
        SourceFiles="@(MySourceFiles)"
        DestinationFolder="$(ProjectDir)bin"
        />
  </Target>

With this target, VS/MSBuild will copy the .dll file to the /bin directory.

Note: Since we have to modify the project file, this fix have to be visible for git source control.

Update:

Could I modify f.ex. Microsoft.DotNet.Props file and add your fix with Target there?

Yes, you can. After test, it works fine. But I need to explain that we are not recommend this solution, because it may effect all the project which have Microsoft.DotNet.targets imported. So when you use this method, you should pay more attention and should back up that Microsoft.DotNet.targets.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • But is the way not to modify each xproj file? May be common bat file or to modify shared Microsoft.DotNet.Common.targets file? – vitm Dec 13 '17 at 06:24
  • @VitalyMosin, To my knowledge, I am afraid you can not use a common bat file to accomplish this. Because we could use wildcard `*.dll` to collect the all binaries, but we could not use the wildcard `*.dll` in the destination folder. Bat file could not smart to put the binaries into the corresponding project bin folder. And for the .targets file, we could do it with .target file, but you still modify each project file to import this .target file to each project. – Leo Liu Dec 13 '17 at 07:45
  • Please look at my upd in question post. I've added xproj content. I see there a couple of imports. Could I modify f.ex. Microsoft.DotNet.Props file and add your fix with Target there? Without local changes in project level.. – vitm Dec 13 '17 at 08:06
  • I've just tried to realize it adding your fix to Microsoft.DotNet.targets and... seems it works for all the projects! So no need make 50 fixes in each project and no need think how to hide it locally from git. I'm just not see clearly how VS using this Microsoft.DotNet.targets for build scenario. Thank you! – vitm Dec 13 '17 at 08:39
  • @VitalyMosin, yes, you can. But you should pay more attention about modifying that file, because it may effect all the project which have Microsoft.DotNet.targets imported. You can check my update answer for detail. – Leo Liu Dec 13 '17 at 08:39
  • Liu, Thanks again! – vitm Dec 13 '17 at 08:41