[英]Update files in visual studio project from build script
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. 目前,我所处的项目之一依赖于第三方API,该API公开了JSON中的大张旗鼓的描述符,我们使用自动休息来生成该描述符,以生成供系统使用的C#文件。
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. C#文件是作为构建脚本的一部分生成的,但是在某些情况下,API已更新,尽管我们不使用任何新更改,但确实会更改某些生成的C#代码,而这又可能取决于从构建脚本输出的新文件,但是VS不知道它们是否存在,因此不包括它们。
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? 因此,我试图找到一种通过构建脚本或其他合理的方式(无需手动更改* .csproj文件)来告诉Visual Studio的方法,以自动将项目中的所有文件包含在其文件夹中,那么有没有办法做到这一点?
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. 我故意没有提到构建脚本技术,因为它并不是很重要,因此,我不介意是否必须使用msbuild任务或其他命令行内容,只要它可以工作,我可能会找到一种将其挂钩的方法。
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. 我也知道有些人会认为“为什么需要继续重新生成文件?”,我们还没有,目前我们尝试保持特定版本,但是忽略了这个问题仍然存在,即如何解决。您是否从VS外部更新VS知道的文件?
You can use wild cards
in .csproj
file. 您可以在.csproj
文件中使用wild cards
。 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. 若要在修改了Visual Studio中的对象列表后阻止Visual Studio扩展通配符,则必须将其添加为属性。
In PropertyGroup
, add a property with like this 在PropertyGroup
,添加具有以下内容的属性
<PropertyGroup>
<IncludeFolder>yourFolder\**</IncludeFolder>
</PropertyGroup>
Then in add the following line to ItemGroup
然后将以下行添加到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. 同样,一旦您从Visual Studio解决方案资源管理器中修改了通配符,Visual Studio将不会对其进行扩展。 (A weird process from Visual Studio) (来自Visual Studio的怪异过程)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.