Wie kann ich verhindern, dass externe MSBuild Dateien im Cache gespeichert werden (von Visual Studio) während eines Projektes bauen?

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

  •  04-10-2019
  •  | 
  •  

Frage

Ich habe ein Projekt in meiner Lösung, die das Leben als C # Bibliothek-Projekt gestartet. Es ist nichts von Interesse daran in Form von Code erhalten, es wird lediglich als eine Abhängigkeit in den anderen Projekten in meiner Lösung verwendet, um sicherzustellen, dass sie zum ersten Mal gebaut werden. Eine der Nebenwirkungen dieses Projektes Aufbau ist auf einen gemeinsam genutzten AssemblyInfo.cs geschaffen, die die Versionsnummer in der Nutzung durch die anderen Projekte enthält.

Ich habe dies getan, indem Sie die folgenden auf die CSPROJ-Datei hinzufügen:

<ItemGroup>
  <None Include="Properties\AssemblyInfo.Shared.cs.in" />
  <Compile Include="Properties\AssemblyInfo.Shared.cs" />
  <None Include="VersionInfo.targets" />
</ItemGroup>
<Import Project="$(ProjectDir)VersionInfo.targets" />
<Target Name="BeforeBuild" DependsOnTargets="UpdateSharedAssemblyInfo" />

Die referenzierte Datei, VersionInfo.targets, enthält die folgende:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <!--
      Some properties defining tool locations and the name of the
      AssemblyInfo.Shared.cs.in file etc.
    -->
  </PropertyGroup>
  <Target Name="UpdateSharedAssemblyInfo">
    <!--
      Uses the Exec task to run one of the tools to generate
      AssemblyInfo.Shared.cs based on the location of AssemblyInfo.Shared.cs.in
      and some of the other properties.
    -->
  </Target>
</Project>

Der Inhalt der VersionInfo.targets Datei einfach in der CSPROJ-Datei eingebettet werden könnte, aber es ist extern, weil ich versuche, all dies in eine Projektvorlage zu drehen. Ich mag die Benutzer der Vorlage das neue Projekt die Lösung, bearbeiten zu können, die VersionInfo.targets Datei hinzufügen und die Build ausgeführt werden.

Das Problem ist, dass sich das Ändern und Speichern der VersionInfo.targets Datei und den Wiederaufbau der Lösung keine Wirkung hat - die Projektdatei verwendet die Werte aus der .targets-Datei, wie sie waren, wenn das Projekt geöffnet wurde. Auch Entladen und das Projekt hat keine Wirkung neu zu laden. Um die neuen Werte zu bekommen, muss ich Visual Studio und öffnen Sie es (oder laden Sie die Lösung).

schließen

Wie kann ich das so einrichten, dass die Konfiguration in die CSPROJ Datei extern ist und nicht zwischengespeichert zwischen baut?

War es hilfreich?

Lösung

I've just answered what appears to be a similar question on this.

How to turn off caching of build definitions in Visual studio

Hopefully it's relevant your issue too.

Andere Tipps

As far as I know, you can't. Visual Studio is not using 'real' MSBuild, it uses an internal build engine that behaves very similar to MSBuild.exe, but still have some subtle differences. This build engine caches the targets, so you have to restart VS once you change something. I believe, it is even documented somewhere, and there is no known workaround (I searched for it about a year ago and found nothing).

You could possibly force the VS to reload the targets via VS API - so, you'll have to create (or find) a custom add-on to do this.

Another option is to use something other than .targets file to store your configuration. For instance, you could use a plain text file and parse it with MSBuild (not that elegant, but it should work).

Upd.

That's what I did some time ago. MSBuild calls an external tool via Exec with WorkingDirectory="$(SolutionDir)", the tool "knows" all the conventions about file names, locations etc., so a working directory is enough to get the job done. Miscellaneous configuration data is stored in the external tool's config, so no problems with caching.

Also, have a look at this question about reading items from a file. I suppose, that better suites your needs.

I had some intermittent success by modifying the project file including the custom msbuild file and making it invalid, then reloading the project, let it stay unloaded, then fixing the project file and reloading.

Sometimes it works, sometimes it doesn't, but better than restarting Visual Studio.

If you need a quick and dirty way to fix it, you may simply reload the solution (via https://stackoverflow.com/a/6877056/182371).

You can do it either by closing-opening the solution file or by hitting Save in an external editor (then when you come back to VS it will asko if you want to reload).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top