简体   繁体   中英

Copy output binaries to custom path for xproj

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.

Ps 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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM