“Appsettings.json” 未被发布。

huangapple go评论89阅读模式
英文:

Appsettings.json aren't beeing published

问题

I am trying to publish my project in Visual Studio Version 17.5.0 through "ClickOnce" but the appsettings.json dont end up in the "Application Files".

Originally i wanted to publish a project twice so that my team can install a "Test" or "Preview" version additionally to the "Production" version but after looking through the web there doesnt seem to be a good solution to this using ClickOnce. I can publish it twice with different names and versions but the application overwrites the existing one eventhough its named different. As it seems it has to do with the assemblyName beeing the same, there is also no good way to automate changing the assemblyName based on publish profile or any other convenient way (I dont want to change the assemblyName manually in the .csproj file everytime)

So what i did was i created a second project that executes the Main method of the original project. I now want to publish my second project as the Preview version for them to "Test" and my original project in order for them to have a working bugfree version at all times they can use incase some major bug surfaces.

The problem is that the appsetting.json files aren't beeing published. It seems they arent included in the deployment manifest but they are copied to the publishDir (my local computer)

Note: The appsettings.json file only exist in the original "Production" project. This only happens when publishing the Preview project that refrences the original, when publishing the original project the appsettings.json are copied / published

I am looking either for a fix to this problem or even better a way to publish the same project so that my team can install both using ClickOnce

I configured the appsettings.json properties as followed:
Build Action: Content
Copy to Output Directory: Copy always / copy if newer

I also added the following to my original .csproj:



Always




appsettings.json
PreserveNewest
PreserveNewest

I added this to my preview .csproj:



Always
Always

The "Publish Status" of the appsettings.json file is also set to "Include (Auto)" in both projects. The Fileshare the project is published to also works fine and all files except appsettings.json are transfered.

英文:

I am trying to publish my project in Visual Studio Version 17.5.0 through "ClickOnce" but the appsettings.json dont end up in the "Application Files".

Originally i wanted to publish a project twice so that my team can install a "Test" or "Preview" version additionally to the "Production" version but after looking through the web there doesnt seem to be a good solution to this using ClickOnce. I can publish it twice with different names and versions but the application overwrites the existing one eventhough its named different. As it seems it has to do with the assemblyName beeing the same, there is also no good way to automate changing the assemblyName based on publish profile or any other convenient way (I dont want to change the assemblyName manually in the .csproj file everytime)

So what i did was i created a second project that executes the Main method of the original project.
I now want to publish my second project as the Preview version for them to "Test" and my original project in order for them to have a working bugfree version at all times they can use incase some major bug surfaces.

The problem is that the appsetting.json files aren't beeing published.
It seems they arent included in the deployment manifest but they are copied to the publishDir (my local computer)

Note:
The appsettings.json file only exist in the original "Production" project.
This only happens when publishing the Preview project that refrences the original, when publishing the original project the appsettings.json are copied / published

I am looking either for a fix to this problem or even better a way to publish the same project so that my team can install both using ClickOnce

I configured the appsettings.json properties as followed:
Build Action: Content
Copy to Output Directory: Copy always / copy if newer

I also added the following to my original .csproj:

<ItemGroup>
  <Content Include="appsettings.json">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.*.json">
            <DependentUpon>appsettings.json</DependentUpon>
	<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
	<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </Content>
</ItemGroup>

I added this to my preview .csproj:

<ItemGroup>
	<Content Include="appsettings.*.json">
		<CopyToOutputDirectory>Always</CopyToOutputDirectory>
		<CopyToPublishDirectory>Always</CopyToPublishDirectory>
	</Content>
</ItemGroup>

The "Publish Status" of the appsettings.json file is also set to "Include (Auto)" in both projects.
The Fileshare the project is published to also works fine and all files except appsettings.json are transfered.

答案1

得分: 1

我找到了一个“解决方法”。
我将appsettings复制到预览项目并更改属性为:

构建操作:内容
复制到输出目录:不复制

此外,我还更改了我的.csproj:

 <ItemGroup>
    <Content Include="appsettings.json" />
	  <Content Include="appsettings.*.json">
		<DependentUpon>appsettings.json</DependentUpon>
	  </Content>
  </ItemGroup>

现在由于某种原因,这些文件在发布时被复制而没有出现错误。

英文:

I have found a "workaround".
I copied the appsettings to the preview project and changed the properties to:

Build Action: Content
Copy to Output Directory: Do not copy

Additionally i changed my .csproj to:

 &lt;ItemGroup&gt;
    &lt;Content Include=&quot;appsettings.json&quot; /&gt;
	  &lt;Content Include=&quot;appsettings.*.json&quot;&gt;
		&lt;DependentUpon&gt;appsettings.json&lt;/DependentUpon&gt;
	  &lt;/Content&gt;
  &lt;/ItemGroup&gt;

Now for some reason the files get copied without getting an error while publishing

huangapple
  • 本文由 发表于 2023年4月13日 18:34:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76004428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定