0

I have a visual studio 2019 and i have a solution.
I have 2 projects in the solution, one of them is a traditional .net core 2.2 web application, and now i have a new one, a python as well.
I need to copy the python project also to the publish folder, so the docker can containerize it. I can not add the python project as a reference to the c# project because it will return with an error: the pyproj can not be found (i am 100% it is in the right way, but i guess it does not copy during building)
I tried to add some extra to msbuild in the csproj file to force copy it, but i guess it does not work because it is out of the project folder and it was not allowed.
I tried to add this lines to the csproj

    <ItemGroup>
        <MySourceFiles Include="..\PYNLP\" />
    </ItemGroup>

and this one also

    <ItemGroup>
        <MySourceFiles Include="$(MSBuildProjectDirectory)\..\PYNLP\" />
    </ItemGroup>

None of them worked well. If anybody has an idea i would be happy to try it.

1 Answer 1

1

I tried to add some extra to msbuild in the csproj file to force copy it, but i guess it does not work because it is out of the project folder and it was not allowed. I tried to add this lines to the csproj

The code which you list did not work because you specify a folder instead of a file, and MySourceFiles must contain specific files.

Just for some suggestions:

To realize that, you have to write a custom target.

First, please use wildcards like *.* to include all files.The core approach which l think you are using is the Copy Task to copy the files into the target folder. And you must specify how the target will run such as AfterTargets or BeforeTargets.

Sample

This is a sample which l have tested successfully and ran without error.

<Target Name="CopyToPublishFolder" AfterTargets="Build">
    <ItemGroup>
      <PythonFiles Include="..\PYNLP\**\*.*" />        
    </ItemGroup>        
   <Copy SourceFiles="@(PythonFiles)" DestinationFiles="@(PythonFiles->'$(PublishUrl)\PYNLP\%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>

In general, when you publish your project by Publish UI, the process contains the Build Target and the target will be executed automatically by Publish UI.

$(PublishUrl) will copy the files into Publish folder directly.

%(RecursiveDir)%(Filename)%(Extension) will keep the file structure of your python project.

In addition, please put the Itemgroup like"PythonFiles" into the custom target in case the input file is mapped to the project again in order to cause confusion when the item is defined globally.

Hope it could help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.