C++/CX Visual Studio 2013 - Include / Reference / Link files Programmatically inside Visual Studio

StackOverflow https://stackoverflow.com//questions/25070516

سؤال

Instead of adding files using the Visual Studio IDE, I need to add files programmatically.

This is because Javascript needs to be added during build-time from a parent folder outside of the project (that is customized based on customer), and moved inside the project at build-time. Although I can move files using the msbuild approach into the project, the project does not reference those files. I googled around for a solution to do this inside the msbuild xml file without any luck. Is there anyway to do this natively through xml parsers?

Please let me know if anyone knows how to do this?

هل كانت مفيدة؟

المحلول

Using the msbuild file (the main project file with .vcxproj extension) I was able to come up with a solution to link the files statically:

  <ItemGroup>
    <None Include="www\**">
      <DeploymentContent>true</DeploymentContent>
    </None>
  </ItemGroup>

and to remove and copy the files over to the needed directory dynamically:

  <Target Name="CleanTarget">
    <Message Text="Clean Target" Importance="high"></Message>
    <RemoveDir Directories="www" ContinueOnError="true" />
    <Message Text="Remove File Command" Condition="Exists('www')" Importance="high"></Message>
  </Target>
  <!-- http://msdn.microsoft.com/en-us/library/3e54c37h.aspx -->

  <Target Name="CopyFiles">
    <Message Text="CopyFiles Target" Importance="high"></Message>
    <Copy
        SourceFiles="@(MySourceFiles)"
        DestinationFiles="@(MySourceFiles->'www\%(RecursiveDir)%(Filename)%(Extension)')"
        />
  </Target>

  <Target Name="BeforeBuild">
    <Message Text="Create Before Build" Importance="high"></Message>  
  </Target>

  <Target Name="AfterBuild">
    <CallTarget Targets="CleanTarget"></CallTarget>
    <CallTarget Targets="CopyFiles"></CallTarget>
  </Target>

My new problem is that the project is only picking up changes from the previous build case. Meaning I need to run the project twice if switching to another javascript folder.

The technical issue is that the BeforeBuild event is not being invoked in my C++/CX application project (I believe that it would work in C# project from threads that I have read off the Internet).

نصائح أخرى

This link solved the "technical" issue from just below:

http://social.msdn.microsoft.com/Forums/en-US/21720645-fed8-4a5d-84ea-1cbcf2796920/beforecompile-beforebuild-fail-to-execute-for-vcxproj-c-projects?forum=msbuild

Although it did not solve the issue with having to compile the project twice when switching in a new js folder. As far as I'm concerned that is not possible. I will check the previous answer (the one just below), unless a better solution is found.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top