简体   繁体   中英

Update files in visual studio project from build script

Scenario

I am in a situation at the moment where one of the projects I am working on depends upon a 3rd party API, which exposes a swagger descriptor in JSON which we consume using auto rest to generate the C# files for use in the system.

The c# files are generated as part of the build script however there have been instances where the API is updated, and although we do not use any of the new changes it does change some of the c# code which is generated which in turn may depend upon new files which are output from the build script but VS does not know they exist so does not include them.

Issue

So I am trying to find a way to tell visual studio from a build script or some sane way (Without manually changing a *.csproj file) to automatically include everything within a folder in its project, so is there a way to do this?

Other Info

I have deliberately not mentioned build script technologies as it is not really important, so I don't mind if I have to use msbuild tasks or other command line stuff as long as it works I can probably find a way to hook it in.

Also I know some people will think "why do you need to keep re-generating the files?", and we don't really, and currently we try to keep to a specific version, however ignoring that the question still stands, ie how do you update files VS knows about from outside VS.

You can use wild cards in .csproj file. You only need to do this once

since you didn't give the folder name, I am suggesting a generic solution for you.

To prevent the Visual studio from expanding the wild card once you modify the porject list in Visual studio, you have to add it as property.

In PropertyGroup , add a property with like this

<PropertyGroup>
    <IncludeFolder>yourFolder\**</IncludeFolder>
</PropertyGroup>

Then in add the following line to ItemGroup

<ItemGroup>
   <Content Include="$(IncludeFolder)" />
</ItemGroup>

This will add everything in that folder to your project.

Also this wild card will not be expanded by the visual studio once you modify them from Visual studio solution explorer. (A weird process from Visual Studio)

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