Pergunta

I have an ASP.NET MVC web application project which also has 2 additional library projects as part of the solution. Within the 2 additional projects I have an assets directory. I was wondering if it was possible to copy the contents of the assets directory to the web application when a build is successful. For example say my application had the following structure:

MyLibraryProject1
    Assets
        Images
            Image1.png
MyLibraryProject2 (this has a dependency on "MyLibraryProject1")
    Assets
        Images
            Image1.png
MyMvcProject
    Controllers
    Views
MyProject.sln

After a successful build the "MyMvcProject" project would then include the following folder:

Assets
    MyLibraryProject1
        Images
            Image1.png
    MyLibraryProject2
        Images
            Image1.png

I originally embedded the resources within the project. However I have found this slowed down the time it took for the application to compile as I have added more assets. I'm open to an alternative solution if anyone has one.

I'd appreciate the help/advice. Thanks

Foi útil?

Solução

you have to go to project properties:

enter image description here

and then you can enter a command in Post-build event or Pre-build event

for copying files you can use xcopy command, here is an example(the commands should work without problem, I tried it):

mkdir "$(TargetDir)\assets\MyLibraryProject1" >nul
mkdir "$(TargetDir)\assets\MyLibraryProject2" >nul
xcopy  /d /e /y "$(SolutionDir)MyLibraryProject1\assets\*" "$(TargetDir)\assets\MyLibraryProject1" >nul
if errorlevel 1 exit 1

xcopy  /d /e /y "$(SolutionDir)MyLibraryProject2\assets\*" "$(TargetDir)\assets\MyLibraryProject2" >nul
if errorlevel 1 exit 1

hope this helps you.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top